java - Ajax call to Rest service not successfully calling success function in ajax -
i having ajax difficulties (and newish ajax, have done fair bit of searching) when calling java rest server have written. have test html page running within rest server (using jetty) , use following call -- works using .get:
$('#getrvlakeform').submit(function(e) { var handle = $('#insertrvlakehandle').val(); var lakekey = $('#rvlakekey').val(); var temp = $('#rvlaketemp').val(); var speed = $('#rvlakewindspeed').val(); var degrees = $('#rvlakewinddegrees').val();; $.get('${pagecontext.request.contextpath}/api/recent/lake/' + handle + "/" + temp + "/" + speed + "/" + degrees + "/" + lakekey, function(data) { alert(data.lake[0].oid); $('#rmlakeresponse').text("back"); });
here json rest server returns:
{"user":[],"lake":[{"oid":"519b9a1a3004f8fa1287502a","type":"lake","handle":"nightstalker","viewedhandle":"","viewedlaketag":"txfork","viewedusername":"","timestamp":1369152026668}]}
this call executes rest api , gets json expected... when attempt call same rest api html/php application, running under mamp -- ajax call works on out bound call -- can debug java rest server , see call come in, , executes designed creating json send out. problem never call success function in ajax call (i not seeing error function called either).
urlrecent = "http://localhost:8080/server/api/recent/lake/" + handle + "/" + temp + "/" + speed + "/" + degrees + "/" + lakekey; $.ajax({ type: "get", contenttype: "application/json", datatype: "jsonp", url: urlrecent, success: function (data) { alert("hello there!"); alert(data) }, error: function () { alert('failed'); } });
i have tried getjson instead..no luck. in mean time continue search stack , web work. have tried datatype of "json" well.
thanks in advance.
=====
yes, munged contenttype, didn't matter.
try in ie8 , set datatype: "html"
urlrecent = "http://localhost:8080/server/api/recent/lake/" + handle + "/" + temp + "/" + speed + "/" + degrees + "/" + lakekey; $.ajax({ type: "get", contenttype: "application/json", datatype: "html", url: urlrecent, success: function (data) { alert("hello there!"); data = json.parse(data); alert(data) }, error: function () { alert('failed'); } });
if syntex error @ data = json.parse(data)
or "hello there" in alert , encoding problem. in case should use response.setcharacterencoding("utf8")
Comments
Post a Comment