2015-08-31 71 views
-1

我創建Web方法,並創建Ajax請求來調用這個Web方法,我有內部服務器錯誤,但是當我從URL調用webservice的直銷工作正常我的Ajax請求:Asp.net Ajax請求(內部服務器錯誤)

$(document).ready(function() { 
    $('#btnsave').click(function() { 
     var x = 'sss'; 
     $.ajax({ 
     url: "/WS/WS.asmx/AddCustomer", 
     type: 'GET', 
     dataType: 'json', 
     data: { CustomerType: x }, 
     contentType: 'application/json; charset=utf-8', 
     error: function (XMLHttpRequest, textStatus, errorThrown){        
      alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown); 
      }, 
      success: function (response) { 
       if (response.d) { 

       } 

      } 
    }); 
}); 

});`

+0

能否請您提供關於500錯誤的更多細節? – JOSEFtw

+0

你想知道什麼細節? – salah

回答

0

試試這個,看(數據: 「{CustomerType: '」 + X + 「'}」)...

$(document).ready(function() { 

      $('#btnsave').click(function() { 
       var x = 'sss'; 

       $.ajax({ 
        url: "/WS/WS.asmx/AddCustomer", 
        type: 'GET', 
        dataType: 'json', 
        data: "{CustomerType:'" + x+ "'}", 
        contentType: 'application/json; charset=utf-8', 
        error: function (XMLHttpRequest, textStatus, errorThrown) { 
         alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown); 
        }, 
        success: function (response) { 
         if (response.d) { 

         } 

        } 

       }); 

     }); 
    }); 
0

我有同樣的錯誤,見下文代碼,它適用於我,雖然如果它不工作,更改類型:'POST'。

$.ajax({ 
     url: 'your URL', 
     type: 'GET', 
     contentType: "application/json; charset=utf-8", 
     datatype: 'JSON' 
    }).fail(function (jqXHR, textStatus, errorThrown) { 
     alert(textStatus + " : " + errorThrown); 
    }).done(function (JSData) {   
     for (var i = 0; i < JSData.length; i++){ 

      //your code 

     } 
    });