tags:

views:

59

answers:

3

Hi ,

I have one string

var str = '';
str += 'category='+jv('category')+'&';

str += 'refresh_rate='+jv('refreshRate')+'&';

str += 'submit=Y';

now I want to take values from jv('category') and jv('refreshRate') in separate string in javascript (I want to extract values after "=" and before "&").

Thanks.

A: 

You can use http://github.com/allmarkedup/jQuery-URL-Parser or any other URL parser for this sort of string.

Māris Kiseļovs
A: 

you can see same question in Stackoverflow: how do I parse a string in javascript or jquery?

Akyegane
A: 

I've used this: http://blog.stevenlevithan.com/archives/parseuri URI Parser in the past and find it simple to use and it doesn't rely on any other libraries. Its also pretty lightweight.

The author has a demo page but doesn't really explain how to use it.. Its really simple, you just do something like this:

var url = "http://my-site.com:8081/index.html?query=go&page=2";
var parsed = parseUri(url);

From there you can get things like the host/protocol/port/etc.. When dealing with the querystring you do

var page = parsed.queryKey.page;
alert(page); //alerts 2

Click the parse button on the demo page to see all properties of the parsed URI object that you can access..

Matt Wolfe