I am using the Intel XDK to create some applications. I need to send an Ajax query to a handler, but the application gives me an error when I send. The query is "pending" in debugging. But in the emulator the Intel XDK query successfully completed. Where is the problem?
There is my JavaScript code:
$.ajax(
{
type: "GET",
url: "mysite.com/php/getList.php",
data: { "faculty": 6 }
})
.done(function( msg )
{
alert( "Data Saved: " + msg );
})
.fail(function( jqXHR, textStatus )
{
alert( "Request failed: " + textStatus );
});
It may be failing because of cross-origin policy. Either your API should support JSONP or have Allow Access Origin * in header.
Or you can include these script tags in your index.html file and then build the app in Intel XDK:
<script src="intelxdk.js"></script>
<script src="xhr.js"></script>
More info here: http://software.intel.com/en-us/html5/articles/how-to-access-JSON-data-in-HTML5-apps
Try firing ajax this way:
$.ajax({
url: "mysite.com/php/getList.php",
type: "GET",
dataType: "json",
data: { "faculty": 6 },
contentType: "application/json; charset=UTF-8",
success: function(data){
console.log("Success");
},
error:function(data){
console.log("Error");
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.