PDA

View Full Version : Ext.Ajax Cross-Domain request



Fabrizio.ExDev
16 Feb 2015, 1:37 AM
Hello.
Is there a way to perform a cross domain post request using Ext.Ajax?

Here's the request's code:
Ext.Ajax.request({
url: 'http://192.168.1.50/test.php',
method: 'POST',
cors: true,
params : {
myParam : testValue
},
useDefaultXhrHeader : false,
success: function () {
alert('success');
},
failure: function () {
alert('failure');
}
});


Here is the error message:
XMLHttpRequest cannot load http://192.168.1.50/test.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.1.60:22800' is therefore not allowed access.

Hope someone can help me,
Thanks to everyone.

jsakalos
16 Feb 2015, 2:06 AM
Yes, but server has to return the mandatory headers. See which headers are returned by http://extjs.eu/api/service.php/cities - that is cross-domain enabled service on my site. Look for Access-Control-* headers.

Fabrizio.ExDev
16 Feb 2015, 11:45 PM
Hello!I'm not really skilled about this, I just see a json object.In any case, I was missing php header like this:
"<?php header('Access-Control-Allow-Origin: *'); ?>"

mitchellsimoens
17 Feb 2015, 2:01 PM
A pretty good CORS resource I've seen is: http://enable-cors.org/