urls in ajax post

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

urls in ajax post

I have some javascript that posts to a contoller in a page and the url paramaters are not working as expected...  well, it's "sort of" working.  When I inspect the Object in the Controller, param1 value is populated with "paramVal1&param2=paramVal2" and param2 value is null.  

var dataStr = "param1" + paramVal1 + "&param2="+paramVal2;
    type: "POST",
    url: "/mySpringController/doSomething",
    data: dataStr,
    dataType: "html",
    success: function(data) {

I have read the docs about constructing urls with @{..} syntax but it's not translating properly in the javascript code which lead's me to believe I am not doing it correctly ;)
Any idea's?
Reply | Threaded
Open this post in threaded view

Re: urls in ajax post

Weird, it's like the query string isn't being split when read at the server.

I'm not sure what's going on here, but I read the jQuery documentation for that 'data' key, and it says that it's appended to the URL for GET requests.  Your ajax request is using POST, so maybe it's getting mixed up because of that?  If so, you might need to put the whole query string into the url key instead.