javascript - How to use ajax post data from a row -


<table>  <tr data-id="1">     <input type="text" name="name_1" value="abc">     <input type="text" name="value_1" value="1">     <a href="load_edit_row(this)">edit</a>  </tr>  <tr data-id="2">     <input type="text" name="name_2" value="def">     <input type="text" name="value_2" value="2">     <a href="load_edit_row(this)">edit</a>  </tr>  <tr data-id="3">     <input type="text" name="name_3" value="ghi">     <input type="text" name="value_3" value="3">     <a href="load_edit_row(this)">edit</a>  </tr> </table>  function load_edit_row(input) {    var id = $(input).parent().attr('data-id');    var datastring = [];     $("tr[data-id="+id+"] :input").each(function(e){        datastring.push(this.value);    });    $.ajax({       type: 'post',       url: 'update-row.php',       data: datastring,       success: function(itemjson) {        },       datatype: 'json'    }); } 

error post data key , data value, how fix it?

you use json.stringify(datastring) encode array in javascript, , use $array=json_decode($_post['string']); in php script retrieve it.

function load_edit_row(input) {    var id = $(input).parent().attr('data-id');    var datastring = [];     $("tr[data-id="+id+"] :input").each(function(e){        datastring.push(this.value);    }); var string = json.stringify(datastring);    $.ajax({       type: 'post',       url: 'update-row.php',       data: 'string='+string,       success: function(itemjson) {        }    }); } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -