JSONP works in jQuery but not in mootools -
i'm trying convert code mootools (i coding paradigm better).
i doing cross-domain ajax own both domains (closed network). requesting simple json server. these errors in mootools (jquery works):
resource interpreted script transferred mime type text/plain. uncaught syntaxerror: unexpected token :
var url = http://localhost:3000/
server:
var http = require('http'), json = {"hi" : false}; http.createserver(function(req, res) { res.writehead(200, {'content-type': 'text/plain'}); res.end(json.stringify(json)); }).listen(3000, function() { console.log("server on " + 3000); }); jquery:
$.ajax({ url: url, type: "get", datatype: 'json', success: function (data) { } }); mootools:
var myrequest = new request.jsonp({ url: url, oncomplete: function (data) { alert(json.stringify(data)); } }); myrequest.send(); i've tried adding these headers no avail.:
'accept': 'application/json', 'content-type': 'application/json' this seems client-side thing , not server-side thing since works in jquery.
what url like? jquery figures out it's jsonp request adding ?callback= or ?foo= url. request.jsonp instead uses option callbackkey.
there's no method option jsonp (in library), since it's injecting script tag.
var myrequest = new request.jsonp({ url: url, callbackkey: 'callback' oncomplete: function(data){} }).send(); i have feeling, however, aren't using jsonp, rather xhr json. if that's case, use request.json, not request.jsonp.
edit
since sounds, comments on answer, you're not using jsonp, this:
new request.json({ url: url, method: 'get', onsuccess: function (data){ console.log(data) } }).send() edit 2
to change request headers add them option:
new request.json({ headers: { 'x-requested-with': 'xmlhttprequest', 'accept': 'text/javascript, text/html, application/xml, text/xml, */*' }, url: url, method: 'get', onsuccess: function (data){ console.log(data) } }).send()
Comments
Post a Comment