Http://www.test.com/Photo_Success.aspx?params={nums:'" + num + "',category:'" + iAlbumId.ToString() + "'}&filenames=" + FileName
上面的这个URL如何获取params里的nums 和category的值。 谢了!
用javascript 接收到params这个参数的值,然后把值用Eval()转换成JSON就可以获取 nums 和category的值
下面函数是获取地址栏值
function getUrlParams() {
var args = new Object();
var query = location.search.substring(1); // Get query string
var pairs = query.split("&"); // Break at ampersand
for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); // Look for "name=value"
if (pos == -1) continue; // If not found, skip
var argname = pairs[i].substring(0, pos); // Extract the name
var value = pairs[i].substring(pos + 1); // Extract the value
value = decodeURIComponent(value); // Decode it, if needed
args[argname] = value; // Store as a property
}
return args;
}
var Params = getUrlParams()["params"];
var object_op = eval(Params);
var nums = object_op.object_op ;
var category = object_op.category;
这个应该可以:
<script language = javascript>
function request(paras){
var url = location.href;
var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
var paraObj = {}
for (i=0; j=paraString[i]; i++){
paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
}
var returnValue = paraObj[paras.toLowerCase()];
if(typeof(returnValue)=="undefined"){
return "";
}else{
return returnValue;
}
}
使用的时候,这样获取参数
var classid = request("nums");
var id = request("category");