XMLHttpRequest cannot load and Sencha touch

∥☆過路亽.° 提交于 2019-12-13 06:25:53

问题


everybody! I have a problem. When i use Ạjax or getStore, i see a error in console Chrome.

XMLHttpRequest cannot load . Origin is not allowed by Access-Control-Allow-Origin.

And, My response result is failed. I don't know this problem relate to this result. Help me, If you have a sulutions. :) Thanks.

When I use Ạjax or getStore, I see an error in Chrome's console.

XMLHttpRequest cannot load. Origin is not allowed by Access-Control-Allow-Origin.

And my response result is failed. I don't know this problem relates to the result.


回答1:


You cannot call any webservice from your browser because of security reasons so either you have to use JSONP proxy on app side or you have to enable CORS on your server side. If you are planning to build this as app then you don't have to do this, all you have to do is change security setting of your browser when you are testing. More details here : How to use json proxy to access remote services during development




回答2:


This problem appears when i code like here:

Ext.Ajax.request({ 
url: 'http://api....api.php/national',
useDefaultXhrHeader: false,
success : function(response, opt) {     
Ext.Msg.alert('Success', response.responseText); 
},
failure : function(response, opt) {
Ext.Msg.alert('Failed', response.responseText); 
}   
});

Or:

var onlineStore = Ext.getStore('NationStore');
 onlineStore.load(); 

This is screen shot about error! Thanks!




回答3:


This appears to be cross domain Ajax call. Browser won't allow it by default. http://en.wikipedia.org/wiki/Same_origin_policy

You need to implement CORS http://en.wikipedia.org/wiki/Cross-origin_resource_sharing



来源:https://stackoverflow.com/questions/17100666/xmlhttprequest-cannot-load-and-sencha-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!