Jquery - using a POST request, which is not allowed Error

前端 未结 2 1500
自闭症患者
自闭症患者 2021-01-12 14:14

I am trying to get jquery to communicate with a web service!!

  function Test(item) {
    $.ajax({
        type: \'POST\',
        url: \'WebService.asmx/Tes         


        
相关标签:
2条回答
  • 2021-01-12 14:17

    Well, use a GET request, then (or change the webservice method to accept POST)

    function Test(item) {
        $.ajax({
            type: 'GET',
            url: 'WebService.asmx/Test',
            data: {Item: item }, /* note change here, data is NOT a string! */
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (msg) {
                alert("oi");
            },
            error: function (msg) {
                alert('Get Details Failure: ' + msg);
            }
        });
    };
    

    Note that the data parameter is NOT a string (and, specifically, it is not JSON). You should pass a JavaScript object.

    0 讨论(0)
  • 2021-01-12 14:44

    Your web service method is marked with a ScriptMethodAttribute that specifies UseHttpGet = true. Try removing this argument, or setting it to false. This is what is preventing the POST from working.

    0 讨论(0)
提交回复
热议问题