0

I am trying to implement jsonp with jQuery but it is not working I did see the example in jsonp with jquery

But in my case it is always making ajax call I am appending &callback=? at the end

I construct relative url like

var url="/pbs/getTraits.do"+ $('#pbstraits').serialize()+"&callback=?"; $.getJSON(url, null, function(data){ document.getElementById("msg").innerHTML = data.message; }); 

is this the right way of doing it?

Also when I am sending query parameters along with url I have to encode which is the best way to do it.

4
  • You don't need JSONP for your own domain. Commented Mar 8, 2013 at 14:07
  • but why its not working Commented Mar 8, 2013 at 14:30
  • How is it not working? What do you see in the dev tools? Commented Mar 8, 2013 at 14:40
  • it is doing an xhr request instead of script request Commented Mar 8, 2013 at 14:41

1 Answer 1

1

jQuery looks for =? in the querystring.
Your URL doesn't have a querystring. (it has no ?)

Instead, you should write

$.getJSON("/pbs/getTraits.do?callback=?"", $('#pbstraits').serialize(), ...); 
Sign up to request clarification or add additional context in comments.

1 Comment

thanks i did what u said but still not change final url generated was localhost:9080/pbs/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.