我的ajax代码如下:
var customername = $('#SelectCustomer').val();
var customercode;
$.ajax({
type: "POST",
url: "OrderFormServices.asmx/GetCustomerCode",
data: { 'customername': customername},
dataType: "json",
cache: false,
success: function (data) {
customercode = data;
$('#hiddenCustomerCode').value = customercode;
}
});
这会返回类似的数据
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">CUST-009012</string>
如何将此值分配给customercode
?
我已经尝试customercode = (data.d);
,但这仍然不起作用
答案 0 :(得分:2)
由于您正在使用jQuery,请将xml
- 响应包装在jQuery对象中并在其上调用find
以获取相应的节点:
$.ajax({
type: "POST",
url: "OrderFormServices.asmx/GetCustomerCode",
data: { 'customername': customername},
dataType: "xml",
cache: false,
success: function (data) {
$customercode= $(data).find("string");
$('#hiddenCustomerCode').val($customercode);
}
});