简体   繁体   中英

jquery ajax request not responding

I'm a newbie at asp.net and trying to understand ajax responses. I have following code:

$(document).ready(function () {
    $('#<%=cbx_pep.ClientID%>').change(function () {
        var mSis = $('#<%=cbx_pep.ClientID%>').val();
        getRCT(mSis);
    });
});

function getRCT(mez_sis) {
    $.ajax({
        url: '/Staff/PEX.aspx/GetTempInfo',
        method: 'get',
        contentType: 'application/json',
        data: '{d_val:' + mez_sis + '}',
        dataType: 'json',
        success: function (data) {
            alert(data.d);
        },
        error: function (error) {
            alert(error);
        }
    });
}

and that's my server side code:

[WebMethod]
public static string GetTempInfo(string d_val)
{
    string str = d_val;
    return str;
}

I'm repeatedly getting error. Appreciate for help.

First, as mybrithname said, You have yo use method: 'post' and then your json is invalid, you have a missing quotes there:

It should be something like this

data: '{d_val:\"' + myVar + '\"}',

你应该使用method: 'post'如果你要将数据发送到服务器,你在data: '{d_val:' + mez_sis + '}'中做的是data: '{d_val:' + mez_sis + '}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM