ajax - JSONP with Jquery 1.9 and Jersey 2.5.1 -


i've googled lot , found nothing suits needs. found these similar threads here, here , here, don't solve problem or don't understand correctly. read jersey documentation couple of times.

i'm developing server side application jersey 2.5.1 , client side html/css/javascript. worked out great, no i'm stumbling. i'm using media-moxy java2json mapper.

@get @jsonp @path("search") @produces({mediatype.application_json, "application/javascript"}) public string findbytagsandboundingbox(@queryparam("topleftlat") double toplat...) {     // work     return json.tostring(); } 

if curl on command line (see accept header request jersey documentation)

curl -x -h "accept: application/javascript" "http://localhost:8181/xxxxx/xxxx/search?topleftlat=59.93704238758132&topleftlon=10.68643569946289&bottomrightlat=59.890573111743336&bottomrightlon=10.806941986083984&tag=restaurant&callback=?" 

jersey deliver content expected (in jsonp):

callback([{"id":3134,"lon" .... }]) 

but if call jquery this:

$.getjson("http://localhost:8181/xxxx/yyyy/search?" + query + "&callback=?", function() {      console.log( "success" ); }) 

i error

 parsererror, error: jquery110207164248435292393_1391195897558 not called  

i can see response in browser contains correct json , 200 return code. reason jquery says wrong.

any kindly appreciated, daniel

callback([{ should have been ?([{ using url used curl.

the purpose of callback parameter in url specify name of callback function should executed. jquery example specified &callback=jquery110207164248435292393_1391195897558 should result in

jquery110207164248435292393_1391195897558([{"id":3134,"lon" .... }]) 

being returned service.

you'll need change line in server code:

@jsonp(queryparam = "callback") 

ref: https://jersey.java.net/documentation/latest/user-guide.html#d0e7040


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -