开发者

jQuery simple ajax request not working

All I want to do is get a page and return the contents of it:

        $.ajax({
开发者_如何学Go            type: "POST",
            url: "alg.aspx",
            data: sqQstring,
            success: function(msg) {
                alert("Data Saved: " + msg);
            }
        });

This doesn't make an alert box and there are no errors in the error console. I've printed out the value of sqQString and it equals:

cc=12&cr=11&sq=10,4|10,4

I've also changed the URL in the ajax to:

http://localhost:2728/shaper/alg.aspx

This makes an alert box but with no data in it.

I've visited the page:

http://localhost:2728/shaper/alg.aspx?cc=12&cr=11&sq=10,4|10,4

And it shows lots of data.

Anyone help?


Add an error handler just to check that you aren't getting an error returned...

   $.ajax({
        type: "POST",
        url: "alg.aspx",
        data: sqQstring,
        success: function(msg) {
            alert("Data Saved: " + msg);
        },
        error: function (request, ajaxOptions, exception){
                alert(request.status);
                alert(exception);
            }    
    });

On top of this, use Firefox with Firebug and watch the "Net" tab to see the actual request and response.

Final comment, if it works when you paste the address into your browser, do a GET request rather than a POST request in your AJAX code.

Possible Solution Based On Comments

$.get("http://localhost:2728/shaper/alg.aspx?cc=12&cr=11&sq=10,4|10,4", 
    function (data) {
        alert("Data Saved: " + data);
    }
);

You can append that querystring dynamically also, but try this first to check it works before changing the example!


Another thing to consider is that your test (when you 'visit the page') is using GET, but your ajax request is POSTing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜