So I'm sending data via jquery.ajax to php which is returning a one value (i.e. the entire php page which only sends one value)
I'd like to pull two values from that php page but how can I split the two values up with jquery?
What I'm trying to achieve is,
- on button click send list item information and ids
- jquery uses ajax to send to php for each list item
- php takes the values and saves them to the database then spits out a new ID
- jquery saves that new ID to the list item that it was previously attached to.
The problem that I'm running into that I can't get jquery to target the old list item. Since I'm using a for loop and the results are inside of a function I can only ever target the last list item.
Here's the code in question, which I thought would have worked, but it didn't.
var i;
for (i = 0; i < updatearray.length; ++i) {
var curval = updatearray[i],
rowid = "#row_"+curval,
text1val = $(rowid+" .text1").val(),
text2val = $(rowid+" .text2").val(),
text3val = $(rowid+" .text3").val();
cardorder = $(".edit_main li:visible").index($(rowid)) + 1;
$.ajax({
type: "POST",
url: "../../study/edit/save.php",
data: { prowid: curval, ptext1val: text1val, ptext2val: text2val, ptext3val: text3val, pdeckid: deckid, pcardorder: cardorder }
})
.done(function( msg ) {
$("#row_"+curval+' button').val(msg);
alert("Data Saved2: " + msg );
});
}
For some reason the "curval" variable will always be the last one in the array. So, to counter this, I could send the correct row via php, but I don't know how to split them up. So I'd want it to look like this basically.
.done(function( newValue, oldValue ) {
$("#row_"+oldValue+' button').val(newValue);
});
If what I'm trying to do is unclear please say so and I'll try to give a more thorough explanation.