簡體   English   中英

如何使用jQuery Ajax通過URL傳遞參數而不刷新頁面?

[英]How to pass parameter through url using jquery ajax without refreshing page?

我正在嘗試使用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);
            }
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM