javascript實現頁面跳轉功能,引數怎麼傳遞?

  • 作者:由 匿名使用者 發表于 舞蹈
  • 2022-07-19

現在要實現下面的功能:

1、首先透過jquery ajax提交表單

2、伺服器響應成功後,使用javascript實現頁面跳轉,比如/test。html

3、伺服器返回的資料,引數怎麼傳遞?資料型別複雜,存在陣列

我把返回的JSON資料轉換成string字串放到當做url的引數傳遞到頁面,這種方式合理嗎?

javascript實現頁面跳轉功能,引數怎麼傳遞?網友66a52d9 2018-03-30

1。設定url

javascript實現頁面跳轉功能,引數怎麼傳遞?

// 設定當前urlvar list_url = ‘/document/order/default。php?page=’ + page_nums + ‘&’+ $(“#form1”)。serialize();var e_list_url = encodeURIComponent(list_url);$(“#list_url”)。val(e_list_url);

2。傳遞url

javascript實現頁面跳轉功能,引數怎麼傳遞?

var list_url = $(‘#list_url’)。val();

window。location。href=‘/document/order/view。php?order_id=’+order_id+‘&action=edit&handler=admin&list_url=’+list_url;

3。解析url並跳轉

javascript實現頁面跳轉功能,引數怎麼傳遞?

var list_url = ‘<?php echo $list_url;?>’;

d_list_url = decodeURIComponent(list_url);window。location。href = d_list_url;

這樣就能實現,引數不丟失了。主要就是頁碼和篩選條件。

純js頁面跳轉要傳複雜資料不好做,要用localStorage,這個東東在各瀏覽器中是不一樣的。

比較好的方法就是,在跳轉連結中加上一些標誌引數,如物件ID之類,直接由伺服器生成新頁面內容或者轉到新頁面後由頁面從伺服器重新ajax取資料。

javascript實現頁面跳轉功能,引數怎麼傳遞?汐日南莘 2015-11-22

可以使用?  &拼接引數

使用window。location。search。substr 獲取傳遞過來的引數

window。location

window的location物件

search

得到的是url中?部分

substr()

返回一個從指定位置開始的指定長度的子字串

這裡設定為1,是為了把url中的?號去掉

split()

將一個字串分割為子字串,然後將結果作為字串陣列返回

這裡就是把?部分以&為分割符,分割

例子:

url:

http://zhidao。baidu。com/question/376679958。html?entry=climb_rock&ishq=1

//獲取連結引數

function GetQueryString(name) {

var reg = new RegExp(“(^|&)” + name + “=([^&]*)(&|$)”);

var r = window。location。search。substr(1)。match(reg);

if (r != null) return unescape(r[2]); return null;

}

var entry = GetQueryString(“entry ”);

console。log(entry ); //列印結果climb_rock

var ishq= GetQueryString(“ishq”);

console。log(ishq); //列印結果1

javascript實現頁面跳轉功能,引數怎麼傳遞?浩海清涵6k 推薦於2018-02-26

可以透過網址引數來傳遞·

A網頁:

$(function(){

$(‘#a按鈕’)。on(‘click’,function(){

//在原頁面跳轉

location。href=“B網頁地址。html?引數名1=引數值1&引數名2=引數值2”

//或者   新開頁面

window。open (‘B網頁地址。html?引數名1=引數值1&引數名2=引數值2’,‘newwindow’,‘height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no’) ;

});

});

B頁面:可以使用js來獲取引數值,程式碼如下:

var parm1 = getParam(‘引數名1’);

var parm2 = getParam(‘引數名2’);

function getParam(paramName) {

paramValue = “”;

isFound = false;

if (this。location。search。indexOf(“?”) == 0 && this。location。search。indexOf(“=”) > 1) {

arrSource = unescape(this。location。search)。substring(1, this。location。search。length)。split(“&”);

i = 0;

while (i < arrSource。length && !isFound) {

if (arrSource[i]。indexOf(“=”) > 0) {

if (arrSource[i]。split(“=”)[0]。toLowerCase() == paramName。toLowerCase()) {

paramValue = arrSource[i]。split(“=”)[1];

isFound = true;

}

}

i++;

}

}

return paramValue;

}

javascript實現頁面跳轉功能,引數怎麼傳遞?herrywood 2012-02-10

純js頁面跳轉要傳複雜資料不好做,要用localStorage,這個東東在各瀏覽器中是不一樣的。

比較好的方法就是,在跳轉連結中加上一些標誌引數,如物件ID之類,直接由伺服器生成新頁面內容或者轉到新頁面後由頁面從伺服器重新ajax取資料

javascript實現頁面跳轉功能,引數怎麼傳遞?杭飛013 2015-12-11

實現介面跳轉時會有個跳轉地址的,可以在跳轉地址後追加,比如 url=“xxx“,可這樣傳遞引數 url + ”?a=xxx&b=xxx“

Top