我收到以下错误:jquery ajax readystate 0 responsetext status 0 statustext error给它时: url(http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm),但是当我url(localhost:""/embparse_page)在本地主机上给它时,它工作正常。
jquery ajax readystate 0 responsetext status 0 statustext error
url(http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm)
url(localhost:""/embparse_page)
我尝试使用在Google搜索中找到的标头,也使用过标头beforeSend:"",但仍然无法正常工作。
beforeSend:""
我认为主要问题是:XMLHttpRequest cannot load http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm. Origin "local server" is not allowed by Access-Control-Allow-Origin.但是我不明白。
XMLHttpRequest cannot load http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm. Origin "local server" is not allowed by Access-Control-Allow-Origin.
任何人都可以向我解释这个问题,因为我对此很陌生。
<!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>
我的情况是,我有一个链接按钮,但我没有使用e.PreventDefault()
ASPX
<asp:LinkButton ID="lnkSearch" runat="server" CssClass="DockCmdSearch" CommandName="Search" OnClientClick="return VerifySearch(this, event);" />
Java脚本
function VerifySearch(sender, e) { e.preventDefault(); $.ajax({ type: 'POST', ............. } return false; }