Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从提要读取JavaScript xmlhttp_Javascript_Xml_Feed - Fatal编程技术网

从提要读取JavaScript xmlhttp

从提要读取JavaScript xmlhttp,javascript,xml,feed,Javascript,Xml,Feed,我正在尝试使用javascript并使用xmlhttp进行读取。我收到一个错误,因为它无法读取 <script type="text/javascript"> url="http://search.yahooapis.com/ WebSearchService /V1/webSearch?appid=YahooDemo &query=persimmon&results=2"; var xmlhttp = null; if (w

我正在尝试使用javascript并使用xmlhttp进行读取。我收到一个错误,因为它无法读取

<script type="text/javascript">
       url="http://search.yahooapis.com/ WebSearchService /V1/webSearch?appid=YahooDemo &query=persimmon&results=2";
       var xmlhttp = null;
       if (window.XMLHttpRequest) 
       {
          xmlhttp = new XMLHttpRequest();
          if ( typeof xmlhttp.overrideMimeType != 'undefined') 
          {
             xmlhttp.overrideMimeType('text/xml');
          }
       } 
       else if (window.ActiveXObject) 
       {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       } 
       else 
       {
          alert('Perhaps your browser does not support xmlhttprequests?');
       }

       xmlhttp.open('GET', url, true);
       xmlhttp.send(null);
       xmlhttp.onreadystatechange = function() 
       {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
           {
            alert("success");
           }
           else 
           {
            alert("failure");
           }
      };
</script>

url=”http://search.yahooapis.com/ WebSearchService/V1/webSearch?appid=YahooDemo&query=persimon&results=2“;
var xmlhttp=null;
if(window.XMLHttpRequest)
{
xmlhttp=新的XMLHttpRequest();
if(typeof xmlhttp.overrideMimeType!=“未定义”)
{
overrideMimeType('text/xml');
}
} 
else if(window.ActiveXObject)
{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
} 
其他的
{
警报('可能您的浏览器不支持xmlhttprequests?');
}
open('GET',url,true);
xmlhttp.send(空);
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
警惕(“成功”);
}
其他的
{
警报(“故障”);
}
};

除非您的网站位于
search.yahooapi.com
上,否则您可能会遇到问题

这导致您的传出请求返回
404
状态代码:

您应该使用而不是
XMLHttpRequest

<!DOCTYPE html>
<html>
 <head>
     <title>JavaScript file download</title>
<script type="text/javascript">
     function yahooApi(resp) {
         var scriptEl = document.getElementById("yahooApiJsonP");
         scriptEl.parentNode.removeChild(scriptEl);
         console.log(resp);
     }

     window.onload = function() {
         var scriptEl = document.createElement("script");
         scriptEl.id = "yahooApiJsonP";
         scriptEl.src = "http://search.yahooapis.com/WebSearchService/V1/webSearch?output=json&callback=yahooApi&appid=YahooDemo&query=persimmon&results=2";
         document.body.appendChild(scriptEl);
     };
</script>
 </head>
 <body>
    <p>This is a test</p>
 </body>
</html>

JavaScript文件下载
函数yahooApi(resp){
var scriptEl=document.getElementById(“yahooApiJsonP”);
scriptEl.parentNode.removeChild(scriptEl);
控制台日志(resp);
}
window.onload=函数(){
var scriptEl=document.createElement(“脚本”);
scriptEl.id=“yahooApiJsonP”;
scriptEl.src=”http://search.yahooapis.com/WebSearchService/V1/webSearch?output=json&callback=yahooApi&appid=YahooDemo&query=persimmon&results=2";
document.body.appendChild(scriptEl);
};
这是一个测试

这将发送请求,返回
200 OK
状态:


它看起来也像:


出现“故障”错误,else零件警报中的块(“故障”)