javascript - retrieve multiple values from ajax call -
so i'm sending info via jquery.ajax php returning 1 value (i.e. entire php page sends 1 value)
i'd pull 2 values php page how can split 2 values jquery?
what i'm trying accomplish is,
on button click send list item info , ids jquery uses ajax send php each list item php takes values , saves them database spits out new id jquery saves new id list item attached to.the problem i'm running can't jquery target old list item. since i'm using loop , results within of function can ever target lastly list item.
here's code in question, thought have worked, didn't.
var i; (i = 0; < 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 reason "curval" variable lastly 1 in array. so, counter this, send right row via php, don't know how split them up. i'd want basically.
.done(function( newvalue, oldvalue ) { $("#row_"+oldvalue+' button').val(newvalue); });
if i'm trying unclear please , i'll seek give more thorough explanation.
you can more 2 values out of php, there ways, think popular though json.
lets in php:
$arr = array( "value_1"=>46534, "value_2"=>654 ); echo json_encode($arr);
you json object:
{"value_1":46534,"value_2":"654"}
and can utilize in promise
$.ajax(...).success(function(data){ var value1 = data.value_1; var value2 = data.value_2; })
javascript php jquery ajax
No comments:
Post a Comment