开发者

Call a PageMethod w/ jQuery using GET

I can call call my ASP.Net page methods fine if I use POST but if I try GET it fails. Any ideas why?

开发者_JS百科
var url = encodeURI(acx.opts.queryURL + "?t=" + acx.input.val());

    acx.requestExe = $.ajax({ type: "GET",
        url: url ,
        //data: "{\"t\":\"" + acx.input.val() + "\"}",     //Data To Send If POST
        contentType: "application/json",                 //Of Request
        dataType: "json",                                //Return Type Expected
        cache: true,
        success: function(d) { showQueryResults(acx,d); },
        error: function(d) 
        { 
            var r = JSON.parse(d.responseText); 
            alert(r.Message);
        }
    }); 


Check your web.config system.web -> httpHandler and make sure your handlers allow the GET verb.


Try to pass data as an object instead:

acx.requestExe = $.ajax({
    type: "GET",
    url: acx.opts.queryURL,
    data: {
        t: acx.input.val()
    },
    contentType: "application/json",
    dataType: "json",
    cache: true,
    success: function(d) {
        showQueryResults(acx,d);
    },
    error: function(d) {
        var r = JSON.parse(d.responseText);
        alert(r.Message);
    }
});


Try specifying option.data:

acx.requestExe = $.ajax({ 
    type:        "GET",
    url:         encodeURI(acx.opts.queryURL),
    data:        "{\"t\":\"" + acx.input.val() + "\"}", 
    contentType: "application/json",                   
    dataType:    "json",                               
    cache:       true,
    success:     function(d) { showQueryResults(acx,d); },
    error:       function(d)   { 
        var r = JSON.parse(d.responseText); 
        alert(r.Message);
    }
});

Instead of manually building it in your querystring:

var url = encodeURI(acx.opts.queryURL + "?t=" + acx.input.val());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜