我必须从服务器读取 XML 请求。如果我在本地保存 XML,一切正常。
脚本:
$(document).ready(function () {
$.ajax({
type: 'GET',
url: 'http://localhost:1410/?SNO=56789&ASQL=plu%20mec%2010;',
crossDomain: true,
dataType: "jsonp",
success: parseXml
});
});
function parseXml(xml) {
$(xml).find('dataset').each(function () {
$("#output").append($(this).find('var[key="article.name"]').text() + "<br />");
});
}
XML 输出:
<document name="screen">
<section name="status">
<dataset>
<var key="organization.number">2919</var>
<var key="organization.name">Testname</var>
<var key="organization.businessdate">09.02.2013</var>
<var key="situation.number">0</var>
<var key="situation.name">Normalbetrieb</var>
<var key="site.number">0</var>
<var key="site.name">Normalbetrieb</var>
<var key="pricelevel.number">1</var>
<var key="pricelevel.name">Standardpreis</var>
<var key="terminal.number">0</var>
<var key="terminal.name">WebKasse</var>
<var key="terminal.status">open</var>
<var key="terminal.tapster">inactive</var>
<var key="waiter.number">1</var>
<var key="waiter.name">Kellner 1</var>
<var key="table.number">5</var>
<var key="table.balance">3.2</var>
<var key="table.sales">3.2</var>
<var key="profile.number">1</var>
<var key="profile.name">Standard</var>
<var key="execution.severity">I</var>
<var key="execution.code">23600003</var>
<var key="execution.message">Mec article list.</var>
</dataset>
</section>
<section name="plu.list">
<dataset>
<var key="type">article</var>
<var key="article.number">1</var>
<var key="article.name">0,1 l Becher Sekt</var>
<var key="article.displayname"/>
<var key="article.price">3.7</var>
<var key="article.plunumber">1</var>
<action key="STANDARD">book plu 1;</action>
</dataset>
[...]
使用此代码,我的页面为空白并显示此错误:
SyntaxError: syntax error
<document name="screen"><section name="status"><dataset><var[...]
奇怪的是:我可以在错误中看到 XML 输出!
如果我更改data type:
为xml
没有错误,页面空白。