![](/img/trans.png)
[英]how to pass parameter value through browser url using jquery ajax request without refreshing page
[英]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.