2

Possible Duplicate:
Parse query string in JavaScript

I have a response that I receive from the server in this format - Status=105&Accno=1458874455&Name=XYZ&Bal=5,888.00 Here '&' signifies separator.

I need to iterate through the string response and split this string in JavaScript based on the '&' and get the values and store them as :

Status=105
Accno=1458874455
Name=XYZ
Bal=5,888.00

so that I can populate them in the respective textbox and drop down.

I am using jQuery and AJAX for receiving the response.

Community
  • 1
  • 1
Sujay
  • 591
  • 1
  • 9
  • 19

2 Answers2

5

You can use split to get the data out:

data = response.split("&");

Once you have the data in the format "key=value", you can split again and add to dictionary:

processed_data = new Object();

for(i = 0; i < data.length, i++){
    m = data[i].split("=");
    processed_data[m[0]] = m[1];
}

You can use the dictionary like:

processed_data["Status"]
ATOzTOA
  • 30,490
  • 20
  • 83
  • 113
1

Use str.split("&") for separating each key value pair. Then use str.split("=") to separate key from pair.

Amber
  • 1,195
  • 8
  • 26