2016-06-29 6 views
0

私のAjaxコードが隠しフィールドに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; 
    } 
}); 

これはどのように私はcustomercodeにこの値を割り当てることができますので、

<?xml version="1.0" encoding="utf-8"?> 
<string xmlns="http://tempuri.org/">CUST-009012</string> 

のようなデータを返します?

私はcustomercode = (data.d);を試してみたが、これはまだあなたがjQueryのを使用しているので、

+0

'$( '#hiddenCustomerCode').val(customercode)'を使用してください.val() 'ajaxからの応答を表示します。 – guradio

+0

また、' dataType: "json" 'dataType:" xml "'?サーバーからXMLデータを取得しています... – Fredster

答えて

2

を働くjQueryオブジェクト内xml -responseをラップし、対応するノードを取得し、それに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); 
    } 
}); 
+0

'dataType:" xml "、' '$ .parseXML(data)'に設定する必要はありますか? – guradio

+0

@guradio:それを固定しました、ありがとう! – eol