Reputation: 33
i'm trying to call an asmx web service, i added the Access-Control-Allow-Origin in the web.config, i added the asmx url in the phonegap whitelisting.
<script type="text/javascript">
$(document).on("ready",onDeviceReady);
function onDeviceReady(){
$.support.cors=true;
$.mobile.allowCrossDomainPages = true;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
crossDomain:true,
dataType: "json",
url:"http://192.168.1.3:812/WebService1.asmx/ObtNegocios",
data: '{}',
success: function(msg) {
for(i=0; i < msg.d.length; i++)
{
$("#details").append($('<li/>').append($('<a/>').attr("href","prueba2.html?id="+msg.d[i].id.Timestamp+"-"+msg.d[i].id.Pid+"-"+msg.d[i].id.Increment+"-"+msg.d[i].id.Machine).text(msg.d[i].nombre)));
console.log(msg.d[i]);
}
$('#details').listview('refresh');
},
error: function(msg) {
alert(msg.d);
console.log(msg);
}
});
}
</script>
the problem appear when i click a list item to see a more detailed information about it
OPTIONS file:///D:/workspace/pruebaPhonegap/assets/www/prueba2.html?id=1375817236-10972-15564611-8618666 Origin null is not allowed by Access-Control-Allow-Origin.
XMLHttpRequest cannot load file:///D:/workspace/pruebaPhonegap/assets/www/prueba2.html?id=1375817236-10972-15564611-8618666. Origin null is not allowed by Access-Control-Allow-Origin.
these are the errors thrown by the chrome console,
Upvotes: 1
Views: 3893
Reputation: 51
IF server Side is PHP you can add below line on the top
header('Access-Control-Allow-Origin: *');
Upvotes: 0
Reputation: 3207
Hi first test on real device , it will solve your issue .
check your confix.xml and add <access origin="*" />
if you need to test in browser use any local server (if php xampp or wampp).
Upvotes: 3