不工作jQuery的简单的Ajax请求简单、工作、jQuery、Ajax

由网友(别说那是曾今丶)分享简介:我想要做的就是一个网页,并返回它的内容:All I want to do is get a page and return the contents of it:$.ajax({type: "POST",url: "alg.aspx",data: sqQstring,success: function(msg) {a...

我想要做的就是一个网页,并返回它的内容:

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

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

这不会使一个提示框,并有在错误控制台没有错误。我打印出来sqQString的价值,它等于:

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

我也改变了AJAX的网址为:

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.

我所访问过的页面:

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

和它显示大量数据。

谁能帮助?

推荐答案

添加一个错误处理程序只是为了检查你没有得到一个错误返回...

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);
            }    
    });

在此之上,使用Firefox使用Firebug和观看网络选项卡中看到实际的请求和响应。

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

最后的意见,如果当你地址粘贴到浏览器中,做一个GET请求,而不是在你的AJAX code POST请求的工作。

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.

根据注释可能的解决方法

$.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!

阅读全文

相关推荐

最新文章