i encountered weird error doing short-polling ajax()-request play2.1-server.
currently using rest send request server , await json answer. server response correct jsonp after short time client gets "parsererror" , stops calling ajax-callbackmethod following requests.
the client:
function restget(url, callback) { $.ajax({ type: 'get', url: 'www. ... /getquestions/42', datatype: 'jsonp', jsonpcallback: 'callbackmethod', success: 'callbackmethod', error: function (jqxhr, status, exception) { console.log('jqxhr: ' + json.stringify(jqxhr)); console.log('restget error: ' + status + ' - ' + exception); } }); } function callbackmethod(response) { console.log('at callbackmethod(' + json.stringify(response) + ')'); }
the server:
public static result getquestions(string lectureid) { string callbackmethod = request().getquerystring("callback"); string json = "{\"question\":\"do find error?\"}"; return ok((callback == null)?json:callback + "("+ json + ")"); }
according fiddler web debugger server sends same (and correct) jsonp-string. , restget-method client called every second.
the client prints out following crashes:
[17:46:24.036] jqxhr: {"readystate":4,"status":200,"statustext":"success"} [17:46:24.036] restget error: parsererror - error: callbackmethod not called
i don't know what's wrong code , other posts found parsererror said have use jsonp instead of json. that's did, didn't i?
function names should not quoted.
function restget(url, callback) { $.ajax({ type: 'get', url: 'www. ... /getquestions/42', datatype: 'jsonp', jsonpcallback: 'callbackmethod', success: callbackmethod, error: function (jqxhr, status, exception) { console.log('jqxhr: ' + json.stringify(jqxhr)); console.log('restget error: ' + status + ' - ' + exception); } }); }
Comments
Post a Comment