Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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 jQuery.find()。每个(fn)在Firefox中都不起作用_Javascript_Jquery_Xml_Firefox - Fatal编程技术网

Javascript jQuery.find()。每个(fn)在Firefox中都不起作用

Javascript jQuery.find()。每个(fn)在Firefox中都不起作用,javascript,jquery,xml,firefox,Javascript,Jquery,Xml,Firefox,我对一个XML文件进行了AJAX调用,下面给出了源代码。它在Chrome中工作得很好,但在Firefox中不起作用。在执行调试时,我看到它没有进入$(response).find(“simpleType”).each(Firefox中的函数()的循环 有人知道我的代码有什么问题吗 $.ajax({ type:"GET", url:"views/workspace/branching_forms/StudentModelDescription.xml", dataType:"xml",

我对一个XML文件进行了AJAX调用,下面给出了源代码。它在Chrome中工作得很好,但在Firefox中不起作用。在执行调试时,我看到它没有进入$(response).find(“simpleType”).each(Firefox中的函数()的循环

有人知道我的代码有什么问题吗

$.ajax({
  type:"GET",
  url:"views/workspace/branching_forms/StudentModelDescription.xml",
  dataType:"xml",
  error:function(XMLHttpRequest, textStatus, errorThrown){
      alert("error="+XMLHttpRequest+" error2="+textStatus+" error3="+errorThrown);
  },
  success:function(response){   
      var i=1;
      console.log("response="+response);
      $(response).find("simpleType").each(function(){                        
         adaptation_type_name[i]=$.trim($(this).find("documentation").text());                                                              
         var restriction = $(this).find("restriction[base=xs:string]");
         j=1;
         var values=new Array();        
         $(restriction).find("enumeration").each(function(){
            var tmp=$(this).attr("value");                                      
            values[j] = tmp;
            j++;
         });
         adaptation_type_variables[i]=values;               
         console.log("adaptation_type_name="+adaptation_type_name[i]+", adaptation_type_variables="+adaptation_type_variables[i]);
         i++;                        
      });                   
      for(var i=1;i<=adaptation_type_name.length;i++)                                       
        $('#adaptation_type_dialog #branching_adaptation_type').append($("<option></option>").attr("value",i).text(adaptation_type_name[i]));

  }
});
$.ajax({
键入:“获取”,
url:“views/workspace/branching_forms/studentmodelsdescription.xml”,
数据类型:“xml”,
错误:函数(XMLHttpRequest、textStatus、errorshown){
警报(“error=“+XMLHttpRequest+”error2=“+textStatus+”error3=“+errorshown”);
},
成功:功能(响应){
var i=1;
console.log(“response=“+response”);
$(响应).find(“simpleType”).each(函数(){
自适应_type_name[i]=$.trim($(this.find)(“documentation”).text());
var restriction=$(this).find(“restriction[base=xs:string]”;
j=1;
var值=新数组();
$(限制).find(“枚举”).each(函数(){
var tmp=$(this.attr(“value”);
数值[j]=tmp;
j++;
});
适应类型变量[i]=值;
console.log(“adaption_type_name=“+adaption_type_name[i]+”,adaption_type_variables=“+adaption_type_variables[i]);
i++;
});                   

对于(var i=1;i根据确保服务器使用正确的mime类型头进行响应。

我以一种非常神秘的方式解决了这个问题。我从所有XML标记中删除了
xs:
名称空间,删除了
并将我的所有XML代码包含在
..
标记中。

您确认了$(响应)。查找(“simpleType”)是否确实返回元素?这是每个代码不运行的最可能原因…是的,$(响应)。find(“simpleType”)返回[object object]它应该返回对象,它是否在对象中有项…尝试检查$(响应)的值。find(“simpleType”).length。这应该显示找到了多少个匹配项,如果它为零,将解释缺少运行代码的原因。$(response.find(“simpleType”).length在Firefox中返回0,在ChromeWell中返回16,这表明它肯定不是失败的。。每个都是失败的,而是选择。我会检查响应是否返回了合理的结果。davin下面的回答听起来可能是错误的一个良好开端。我曾尝试将proxy.php文件与以下内容一起使用t:header('Content-type:text/xml');echo file_get_contents('StudentModelDescription.xml');在ajax url中,我连接到proxy.php,但仍然无法解决问题。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="browser" id="context_browser">
      <xs:annotation>
          <xs:documentation xml:lang="en">Web Browser</xs:documentation>
      </xs:annotation>
      <xs:restriction base="xs:string">
          <xs:enumeration value="Safari" id="1" />
          <xs:enumeration value="Google Chrome" id="2" />
          <xs:enumeration value="Opera" id="3" />
          <xs:enumeration value="Mozilla Firefox" id="4" />
          <xs:enumeration value="Internet Explorer" id="5" />
      </xs:restriction>
  </xs:simpleType>    
  <xs:simpleType name="networktype" id="context_networktype">
      <xs:annotation>
          <xs:documentation xml:lang="en">Network Type</xs:documentation>
      </xs:annotation>
      <xs:restriction base="xs:string">
          <xs:enumeration value="ADSL2+/Cable (High capacity)" id="1" />
          <xs:enumeration value="ADSL / HSPA (Moderate capacity)" id="2" />
          <xs:enumeration value="Dialup / GPRS (Low capacity)" id="3" />
      </xs:restriction>
  </xs:simpleType>
</xs:schema>