0

I am trying to update my database using AJAX. I have a form which contains text fields. I POST those values using serialize function in j query. Got output: Firstname=Sometext1&Lastname=Sometext2&Phone=12345

Then i used the split() function so the result is

Firstname=Sometext1,Lastname=Sometext2,Phone=12345

Now how do I use these values to insert into my database. How can I get individual values i.e. Sometext1,Sometext2,12345 in different variables

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

easiest way would be to use a second split and loop through the output:

var input = "Firstname=Sometext1&Lastname=Sometext2&Phone=12345";
var split = input.split("&"); //["Firstname=Sometext1","Lastname=Sometext2","Phone=12345"]

var output = [];

//loop through split
for(var i=0;i<split.length;i++){
    var subSplit= split[i].split("="); //split up each value again
    output.push(subSplit[1]); //subSplit[0] would be the key, subSplit[1] the value
}

console.log(output); //output: ["Sometext1","Sometext2","12345"]

...would be easier to give better advice if we knew more of your code, tough...especially the reason why the data is serialized that way would be interesting...

Mr.Manhattan
  • 5,315
  • 3
  • 22
  • 34