1. 程式人生 > >thinkphp使用ajax提交後怎麼做頁面跳轉

thinkphp使用ajax提交後怎麼做頁面跳轉

我的登陸頁面是用ajax提交的。提交成功後除了顯示登陸成功的提醒資訊外,還會返回一個url給js做頁面跳轉。
如下: http://127.0.0.1/demo/Home/User/login.html
提交表單後,後臺返回一個jumpUrl="Home/Index", 用U('Home/Index')函式生成的。
然後在表單提交的回撥函式裡這樣寫
  1. $.post(_post_url,data,function(result){
  2. if(result.code>0){//失敗
  3. $("#msg").html(result.msg);
  4. }else{//成功
  5. $("#msg").html(result.msg);
  6. setTimeout("location.href='"+result.jumpUrl+"'",1000);
  7. }
  8. });
複製程式碼 這個時候頁面會跳轉到http://127.0.0.1/demo/Home/Home/Index.html
多了一個Home.