2012-08-14 69 views
0

我正嘗試撥打另一個文檔來獲取電話號碼。不幸的是,它似乎沒有正常工作,並且不會拉出正確的電話號碼。有沒有一種方法可以在代碼中設置電話號碼?目前我的代碼看起來像這樣:通過ajax設置電話號碼

function setTollNo() { 
     $.ajax({ 
      type: "POST", 
      url: "/PURLService.asmx/GetTollNo", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function(html) { 
       $("[id*=tollNo]").html(html.d); 
      }, 
      error: function() { alert('error'); } 
     }); 
    } 

我可以把一些東西沿着以下幾行?

tollNo = 18005557755

+0

如果添加alert(「response:」+ html.d),你會看到什麼? – Dave 2012-08-14 16:47:52

+0

這是我用錯誤的號碼得到的迴應。響應1-855-281-5195 – maddev 2012-08-14 16:50:30

+0

你期望html.d包含什麼? /PURLService.asmx/GetToll沒有文檔或內部服務的某些公共服務?它期望有任何參數嗎?你沒有通過任何我能看到的東西。 – Dave 2012-08-14 20:05:56

回答

0

我認爲你正在尋找

function setTollNo() { 
    $.ajax({ 
     type: "POST", 
     data: { tollNo: '18005557755' }, 
     url: "/PURLService.asmx/GetTollNo", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function(html) { 
      $("[id*=tollNo]").html(html.d); 
     }, 
     error: function() { alert('error'); } 
    }); 
} 

轉至jQuery.ajax文檔並搜索 「例子」。