-
28 May 2012 5:48 AM #1
Answered: Origin http://localhost is not allowed by Access-Control-Allow-Origin
Answered: Origin http://localhost is not allowed by Access-Control-Allow-Origin
SALAM all.
when i'm tring to execute Ext.Ajax.request({ function, ann error appear. i'm using google chrom to test my app. here is my code:
Code:Code:varurtemp = Ext.getCmp('Login').getValue()+"/"+Ext.getCmp('password').getValue(); Ext.Ajax.request({ url: 'http://localhost:8732/log/log/'+urtemp, success : function(response) { Ext.getCmp('res').setValue(response.responseText); var user = eval('('+ response.responseText+ ')'); App.variable = user.clientID; var nv = user.clientNOM; var pr = user.clientPRENOM; if(nv !== "null") { // console.log(App.variable); Ext.Msg.alert("Bienvenue Monsieur",pr+" "+nv); Ext.redirect('Banking/compte'); window.location = redirect; } else {Ext.Msg.alert("Mot de passe ou login incorrecte","veuillez reeseyer");} }, failure: function(response) { Ext.getCmp('res').setValue(response.status); } });
im using google chrom to test my app.
the error is
[COLOR=red !important]Failed to load resource: the server responded with a status of 405 (Method Not Allowed) http://localhost:8732/log/log/admin/...=1338212400945[/COLOR]
[COLOR=red !important]XMLHttpRequest cannot load http://localhost:8732/log/log/admin/...=1338212400945. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
[/COLOR]
and the response.status is 0
and even i test it on an Android Emulator, i have the same response.status = 0
how can i fix it. thank you.
[COLOR=red !important]
[/COLOR]
-
Best Answer Posted by steve1964
Hi, in the Android Emulator you dont have access to localhost (http://127.0.0.1) .
http://stackoverflow.com/questions/6...droid-emulator
-
30 May 2012 6:00 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
You are trying to work with CORS (cross origin resource). Does your server support CORS?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
30 May 2012 7:31 AM #3
SALAM.
thank you for your response. i fixed it but adding in the shortcut of google chrome : --disable-web-security
and adding to IIS : "Access-Control-Allow-Origin" "*" and now it's work correctly in my browser.
but my target is to build a mobile app, so i tested it on an Android emulator, but it's failed to consume my web service. i work on localhost. ==> the response.status is "0". I tried another thing, i put Ext.data.jsonp instead of Ext.ajax.request, without success. have you any idea to correct my code.
-
30 May 2012 7:52 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
You switched to JsonP but did you update your response to be valid?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
30 May 2012 8:35 AM #5
how can i update it ?
my response is a json file
there is a modification should be i do ?Code:{"LOGIN":"admin","PASSWORD":"admin","clientADRESSE":"zouhour","clientCODE":"9876","clientID":"1234","clientNOM":"jouini","clientNUMTEL":"21212121","clientPRENOM":"zied","comptes":[],"demandes":[]}
-
30 May 2012 8:56 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
JsonP requires the JSON to be wrapped in a callback function which the name of that function is passed as the callback parameter in the request.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
4 Oct 2012 6:54 AM #7
Could you perhaps give an example of the format expected when the json response is wrapped within the callback function please mitchell?
-
13 Oct 2012 7:21 AM #8
Hi, in the Android Emulator you dont have access to localhost (http://127.0.0.1) .
http://stackoverflow.com/questions/6...droid-emulator
-
14 Oct 2012 11:55 PM #9
Worked it out, for anyone with a similar query the wrapped json response should take the format:
Ext.data.JsonP.callback1({Your JSON})
Note the callback part is incremented per subsequent call and will need to be handled by the server side web service when generating a response, i.e. callback2, callback3 and so on.


Reply With Quote