xmlhttprequest - MooTools CORS request vs native Javascript -


i have mootools code:

new request.json({   method: 'post',   url: url, /*url domain*/   onsuccess: function(r){     callback(r);   } }).post(data); 

and code doesn't send post requests (options only)... @ code below (it works great):

var http = null,   params = object.toquerystring(data); try {   http = new xmlhttprequest(); } catch (e) {   try {     http = new activexobject("msxml2.xmlhttp");   } catch (e) {     try {       http = new activexobject("microsoft.xmlhttp");     } catch (e) {       http = null;       alert("your browser not support ajax!");     }   } } var url = url; http.onreadystatechange = function () {   if (http.readystate == 4 && http.status == 200) {     var jsondata = json.parse(http.responsetext); /*or eval*/     callback(jsondata);   } }; http.open("post", url); http.setrequestheader("content-type", "application/x-www-form-urlencoded"); http.send(params); 

edit:

tried: .setheader('content-type','application/x-www-form-urlencoded');
still nothing... can there problem?

thanks!

this because mootools bundles stuff request headers.

eg. if htaccess says:

header set access-control-allow-origin: * 

you need craft request that:

var foo = new request({     url: 'http://fragged.org/epitome/example/data/',     method: 'get',     oncomplete: function (data) {         // returns object name , surname           new element('div[html="{name} {surname}"]'.substitute(json.decode(data))).inject(document.body);     } });  // need remove or cors need match delete foo.headers['x-requested-with']; foo.send();     

this why seeing options pre-flight. not :)

you change .htaccess match x-requested-with, "security".

see http://jsfiddle.net/7zusu/1/ working example - did while ago when wanted change request https://github.com/mootools/mootools-core/issues/2381 fixed.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -