我有一个返回XML字符串的Ajax调用,但是我无法访问结果:
function testLimitePanier() {
var reponse = [];
$.ajax({
type: "POST",
url: urlsite + 'limite-panier.php',
success: function(xml){
console.log(xml);
reponse['result'] = $('result', xml).text();
reponse['message'] = $('message', xml).text();
}
});
console.log(reponse);
return reponse;
}
XML日志返回正常
<result><![CDATA[KO]]></result>
<message><![CDATA[some text]]></message>
但是响应为空。我认为jQuery有问题;如何在纯Javascript中做同样的事情?感谢您的帮助。
答案 0 :(得分:0)
当它不包装在CDATA中时,将可寻址:
public async Task<DataTable> GetClients()
{
var ds = new DataSet();
using (var conn = new SqlConnection(CMS))
{
using (var cmd = new SqlCommand("[dbo].[ClientsReturn]"))
{
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
await conn.OpenAsync();
var adapter = new SqlDataAdapter(cmd);
await Task.Run(() => adapter.Fill(ds));
var T = ds.Tables[0];
return T;
}
}
}
$(`<result><![CDATA[KO]]></result>
<message>Some text</message>`).each(function() {
console.log($(this).text())
});