5 回答

TA貢獻1799條經(jīng)驗 獲得超6個贊
sx/ajax提交成功后采用以下方式跳轉(zhuǎn):
1、本頁面跳轉(zhuǎn):"window.location.href"、"location.href"
2、上一層頁面跳轉(zhuǎn):"parent.location.href"
3、最外層的頁面跳轉(zhuǎn):"top.location.href"
@RequestMapping(value="searchUser")
publicvoidsearchHome(HttpServletResponseresponse){
Stringresult=null;
...
查詢用戶的方法
...
if(查詢成功){
result=JsonUtil.objectToJson(查詢結(jié)果對象);//結(jié)果對象轉(zhuǎn)化成Json字符串,在ajax的結(jié)果中跳轉(zhuǎn)到用戶詳情的處理方法
AjaxUtil.ajax(response,result);
}else{//查詢失敗,返回提示信息
AjaxUtil.error(response,"查詢用戶失敗");
}
}
擴展資料
jsp頁面的ajax:
此處的重點在于如何在ajax的回調(diào)函數(shù)中調(diào)用普通方法,并將之前查詢出的用戶數(shù)據(jù)傳到普通方法中(上面?zhèn)未a中紅色的部分),繼而跳轉(zhuǎn)到用戶詳情頁面。
在body中寫隱藏的form表單,在回調(diào)函數(shù)中把查到的用戶數(shù)據(jù)復制給form表單中的input,然后提交表單跳轉(zhuǎn)到普通方法中,這樣就是以post方法提交的數(shù)據(jù),并且可以跳轉(zhuǎn)到新頁面。

TA貢獻2019條經(jīng)驗 獲得超9個贊
$.ajax({
type:"POST",
url: //你的請求程序頁面隨便
async:false,//同步:意思是當有返回值以后才會進行后面的js程序。
data://請求需要發(fā)送的處理數(shù)據(jù)
success:function(msg){
if (msg) {//根據(jù)返回值進行跳轉(zhuǎn)
window.location.href = '你的跳轉(zhuǎn)的目標地址';
}
擴展資料:
關(guān)于上述跳轉(zhuǎn)的注意事項
1、ajax只接受最后返回的值,不會響應跳轉(zhuǎn)請求更改瀏覽器地址欄地址轉(zhuǎn)向的,你需要用js判斷ajax的返回值是否要跳轉(zhuǎn),然后設置location.href實現(xiàn)跳轉(zhuǎn)。
2、ajax異步請求struts的action只會返回所請求頁面的html源代碼,這樣請求是不會跳轉(zhuǎn)的,這種用法只是在替換頁面局部html時使用。
3、在springMVC框架中,當controller層方法返回String類型的時候默認是進行頁面跳轉(zhuǎn),這時候后臺使用return時ajax接收到的并不是后臺返回的某個字符串或狀態(tài)碼,而是整個html對象,這時可以在后臺的方法上添加注解 @ResponseBody。
4、無法從ajax函數(shù)外部獲取ajax請求到的數(shù)據(jù),在需要使用數(shù)據(jù)的組件之前,先在ajax回調(diào)函數(shù)中使用localstorage.setItem()將數(shù)據(jù)儲存在本地,在組件中使用localstorage.getItem()調(diào)用。
在此過程中嘗試在componentWillMount 中用 setState 來傳遞數(shù)據(jù),但是報錯,錯誤的大致內(nèi)容是 setSate 必須在component 的 mounting和mounted狀態(tài)下才能使用。

TA貢獻1845條經(jīng)驗 獲得超8個贊
首先ajax即“Asynchronous Javascript And XML”,即無刷新頁面提交;
主要語法:
1234 | $.ajax({ url: "test.html" , context: document.body, success: function (){ $( this ).addClass( "done" ); }}); //其中,url為請求路徑,context為請求參數(shù),success為回調(diào)函數(shù); |
如果你想要跳轉(zhuǎn)到另外一個頁面,可以使用location.href()方法,即在回調(diào)函數(shù)當中寫;代碼如下:
1234567 | $.ajax({ url: "test.html" , context: document.body, success: function (){ location.href= "跳轉(zhuǎn)的頁面" ; location當然還有很多類似的跳轉(zhuǎn)方法,如window.open,或者 window.location.href等 傳參數(shù),直接 location.href= '跳轉(zhuǎn)頁面' +?“參數(shù)” }}); |

TA貢獻1856條經(jīng)驗 獲得超11個贊
jsx/ajax提交成功后采用以下方式跳轉(zhuǎn):
1、本頁面跳轉(zhuǎn):"window.location.href"、"location.href"
2、上一層頁面跳轉(zhuǎn):"parent.location.href"
3、最外層的頁面跳轉(zhuǎn):"top.location.href"
舉例說明:
如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js這樣寫
"window.location.href"、"location.href":D頁面跳轉(zhuǎn)
"parent.location.href":C頁面跳轉(zhuǎn)
"top.location.href":A頁面跳轉(zhuǎn)
如果D頁面中有form的話,
<form>: form提交后D頁面跳轉(zhuǎn)
<form target="_blank">: form提交后彈出新頁面
<form target="_parent">: form提交后C頁面跳轉(zhuǎn)
<form target="_top"> : form提交后A頁面跳轉(zhuǎn)
添加回答
舉報