the*_*ans 5 javascript jquery xsd
我正在从 AJAX 调用返回自定义架构数据,并且需要使用 jQuery 对其进行解析。知道如何做到这一点吗?
这是 XML:
<xsd:get_customer_summary_response xmlns:xsd="http://com/acmeco/ovm/cas/xsd">
<xsd:customer_details>
<typ:phone_number xmlns:typ="http://com/acmeco/ovm/cas/types">1.555.5553002</typ:phone_number>
<typ:timezone xsi:nil="true" xmlns:typ="http://com/acmeco/ovm/cas/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<typ:zipcode xmlns:typ="http://com/acmeco/ovm/cas/types">3002</typ:zipcode>
...
</xsd:customer_details>
</xsd:get_customer_summary_response>
Run Code Online (Sandbox Code Playgroud)
这是 AJAX 调用。我可以使用下面的内容解析普通的 XML,但不能解析 XSD 的内容。
$.ajax({
type: "GET",
url: "so.xml",
dataType: "html",
success: function(returnhtml){
$("customer_details", returnhtml).find("zipcode").each(function() {
alert($(this).text());
});
}, etc.
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我没有测试过这个,但你尝试过:
$.ajax({
type: "GET",
url: "so.xml",
dataType: "html",
success: function(returnhtml){
$(returnhtml).find("customer_details zipcode").each(function() {
alert($(this).text());
});
}, etc.
Run Code Online (Sandbox Code Playgroud)
jQuery 的参数context需要一个 DOM 元素。
returnhtml将是一个 HTML 字符串,具体取决于jQuery's ajax() documentation您是否将其设置dataType为 HTML。如果它是 XML 字符串,则需要先让 jQuery 将其转换为可以使用的元素,然后再将其用作上下文。
| 归档时间: |
|
| 查看次数: |
8071 次 |
| 最近记录: |