Ho ricevuto il seguente errore: jquery ajax readystate 0 responsetext status 0 statustext error
quando lo ha fornito: url(http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm)
, tuttavia funziona correttamente quando lo prendo url(localhost:""/embparse_page)
sul mio localhost.jquery ajax readystate 0 stato di responsetext 0 statustext errore
Ho provato a utilizzare le intestazioni che ho trovato su una ricerca di Google, e ho usato anche beforeSend:""
, ma non funziona ancora.
Penso che il problema principale sia: XMLHttpRequest cannot load http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm. Origin "local server" is not allowed by Access-Control-Allow-Origin.
ma non lo capisco.
Qualcuno può spiegarmi il problema, visto che sono abbastanza nuovo in questo.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ng="http://angularjs.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta Access-Control-Allow-Origin="*" />
<title>Page Parsing</title>
<script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
<script>
getit=function(){
jQuery.support.cors = true;
$.ajax({
type:"GET",
url:"http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm",
dataType:"html",
crossDomain:true,
beforeSend: function(xhr) {
xhr.overrideMimeType('text/plain;charset=UTF-8');
},
success:function(XMLHttpRequest,jqXHR ,data) {
//alert(data.title);
var starttitl=data.lastIndexOf('<title>');
var endtitl=data.lastIndexOf('</title>');
var title1=data.substring(starttitl+7,endtitl);
alert(title1);
},
error:function(errorStatus,xhr) {
alert("Error"+JSON.stringify(errorStatus));
}
});
}
</script>
</head>
<body>
<div id="siteloader">
<input type="button" onclick="getit()" />
</div>
</body>
</html>
Un consiglio: non utilizzare avviso in quanto è il modo più irritante per eseguire il debug. Prova 'console.log' e premi F12 in Chrome o control + shift + k in firefox per aprire la console. Ci sono molti strumenti che puoi usare come impostare i breakpoint e ispezionare le richieste con le intestazioni di richiesta e risposta. – HMR
grazie signore per il suggerimento –
La top rated risposta su questo post è abbastanza in profondità: http://stackoverflow.com/questions/15005500/loading-cross-domain-html-page-with-ajax – Adrian