开发者

Process hash fragment using JavaScript

i want to get hash parameters value in my java script for example my url should be like that

www.example.c开发者_如何学编程om/#!mydata=data&myopt=option

i want to get mydata in variable which will be "data" as value, and myopt "option"

iam trying to implement google ajax cowling like here Google Code

and i have tried to implement jquery address

but with big fail so help me either by solving 1st part or give me simple walk through tutorial to implement jquery address to my ajax requests ,thank you


This piece of code will convert any well formed (i.e. properly url-encoded) request string into an object literal with values parsed.

var s = "#!mydata=data&myopt=option";
var o = {};

$.each(s.substr(2).split('&'), function(i, elem) {
   var parts = elem.split('=');
   o[parts[0]] = parts[1];
});

Then you can access values like o.myopt

UPDATE

Of course, to get the value from browser's address, you should use

var s = window.location.hash;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜