Sent data to the server - empty params

89 views
Skip to first unread message

Édipo Luis Féderle

unread,
Aug 12, 2015, 9:15:46 AM8/12/15
to ClojureScript

Hello again,

I am working with base om tutorial by David Nolan. But I am with a problem when I try send a POST to my back-end. Basically I use the same code from om tutorial. I test back-end separately e it works as expects:

curl -X POST -d "foo=bar" http://localhost:10555/posts
Params: {:foo "bar"}%

Bu when I trying from ClojureScript the params is empty. I do:

Code from Om tutorial:

(def ^:private meths
{:get "GET"
:put "PUT"
:post "POST"
:delete "DELETE"})

(defn edn-xhr [{:keys [method url data on-complete]}]
(let [xhr (XhrIo.)]
(events/listen xhr goog.net.EventType.COMPLETE
(fn [e]
(on-complete (reader/read-string (.getResponseText xhr)))))
(. xhr
(send url (meths method) (when data (pr-str data))
#js {"Content-Type" "application/edn"}))))

The request:

(edn-xhr
{:method :post
:url (str "posts")
:data {:name "Foo Bar"}
:on-complete
(fn [res]
(println "server response:" res))})
)

;;=> server response:

I don't figured out whats is the problem here. If I missed some important information in this post, please, let me know.

Thanks in advance.

Message has been deleted

Gary Verhaegen

unread,
Aug 14, 2015, 7:45:47 AM8/14/15
to clojur...@googlegroups.com
It's difficult to tell without the server code, but I think this is a
misunderstanding about what HTTP params are. In your manual case, you
are sending "www-url-encoded post params", while in your cljs example
you're sending a request with an EDN body. These two approaches yield
very different HTTP requests at the wire level, and your server code
has to unpack them differently. Depending on your Ring wrappers, the
EDN you send from cljs will probably be in the :body (not :params)
attribute of the ring request, and may be either a Clojure map or a
string.

On 12 August 2015 at 15:31, Édipo Luis Féderle <edipof...@gmail.com> wrote:
> On Wednesday, August 12, 2015 at 10:15:46 AM UTC-3, Édipo Luis Féderle wrote:
>> Hello again,
>>
>> I am working with base om tutorial by David Nolen*. But I am with a problem when I try send a POST to my back-end. Basically I use the same code from om tutorial. I test back-end separately e it works as expects:
> David Nolen*
> --
> Note that posts from new members are moderated - please be patient with your first post.
> ---
> You received this message because you are subscribed to the Google Groups "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
> To post to this group, send email to clojur...@googlegroups.com.
> Visit this group at http://groups.google.com/group/clojurescript.

Édipo Luis Féderle

unread,
Aug 14, 2015, 10:44:45 AM8/14/15
to clojur...@googlegroups.com
Yes, Gary,

I fix it and now everything works fine :).

Thanks

You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/ddwLLRIygiE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.

To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.
Reply all
Reply to author
Forward
0 new messages