Javascript 如何使用jQueryAjax通过url传递参数而不刷新页面?

Javascript 如何使用jQueryAjax通过url传递参数而不刷新页面?,javascript,jquery,asp.net,ajax,Javascript,Jquery,Asp.net,Ajax,我正在尝试使用Asp.Net中的Get方法传递参数。但地址栏中的url并没有改变 请任何人帮助我通过url使用ajax调用传递参数 我的一些尝试如下:考虑URL低于 var obj = { templateName: templateName, pageIndex: pageIndex }; $.ajax({ type: "GET", contentType: "application/json; charset=u

我正在尝试使用Asp.Net中的Get方法传递参数。但地址栏中的url并没有改变

请任何人帮助我通过url使用ajax调用传递参数

我的一些尝试如下:考虑URL低于

        var obj = { templateName: templateName, pageIndex: pageIndex };
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: "result.aspx/DisplayResult",
            // data: "{'templateName':'" + document.getElementById('txtSearch').value + " &pageIndex : '" + pageIndex + "'' }",
            data: JSON.stringify(obj),
            dataType: "json",
            success: OnSuccess,
            error: function (result) {
                alert(result.value);
            }
        });

您的AJAX请求看起来不错,但没有理由更改URL。如果您的请求成功,将由
OnSuccess
功能处理。但是,我看不到您在哪里定义了
onSuccess
引用的函数。试试这个:

   var obj = { templateName: templateName, pageIndex: pageIndex };
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: "result.aspx/DisplayResult",
            // data: "{'templateName':'" + document.getElementById('txtSearch').value + " &pageIndex : '" + pageIndex + "'' }",
            data: JSON.stringify(obj),
            dataType: "json",
            success: function (response) {
              // You should see the response object in your dev console
              console.log(response);
              // If you want to manipulate the URL for some reason after a successful callback,
              // do that here, or better, call a function referenced elsewhere that does it.
            },
            error: function (result) {
                alert(result.value);
            }
        });

您不需要在
obj
上应用
JSON.stringify()
。应该是:
data:obj,…
以问题中提到的方式传递数据有什么问题??如果您想更改url,您可以通过javascript代码进行更改,并且仍然像以前一样传递数据。如果您只想通过url传递数据,您应该使用POST方法而不是GET。但是在url中,我没有找到通过参数传递的变量。我不太确定您在问什么。您的意思是,当GET请求从服务器返回后,浏览器中的URL没有更改吗?是的,我必须在页面更改时更改浏览器中的URL,或者单击“上一步”按钮而不刷新页面。