<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'
});
}
发布数据密钥和数据值时出错,如何解决?
答案 0 :(得分:1)
您可以使用JSON.stringify(dataString)
在JavaScript中对数组进行编码,然后在PHP脚本中使用$array=json_decode($_POST['string']);
来检索它。
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) {
}
});
}
答案 1 :(得分:0)
尝试类似:
libname LIBRARYNAME 'filesource...'
data Project2
set exdata.Project;
<math>
run;
答案 2 :(得分:0)
<table>
<tr id="1">
<input type="text" name="name_1" id="1-data1" value="abc">
<input type="text" name="value_1" id="1-data2" value="1">
<a href="load_edit_row(1)">Edit</a>
</tr>
<tr data-id="2">
<input type="text" name="name_2" id="2-data1" value="def">
<input type="text" name="value_2" id="2-data2" value="2">
<a href="load_edit_row(2)">Edit</a>
</tr>
<tr data-id="3">
<input type="text" name="name_3" id="3-data1" value="ghi">
<input type="text" name="value_3" id="3-data2" value="3">
<a href="load_edit_row(3)">Edit</a>
</tr>
</table>
现在JS:
function load_edit_row(input) {
var dataString = [];
dataString.push($("#"+input+"-data1").val());
dataString.push($("#"+input+"-data2").val());
});
$.ajax({
type: 'POST',
url: 'update-row.php',
data: dataString,
success: function(itemJson) {
},
dataType: 'json'
});
}
答案 3 :(得分:0)
您不能简单地将一个javascript 0索引数组发送到POST Form Data
,并期望在服务器端正确接收它。
将JSON.stringify(dataString)
格式dataString
用于json
字符串,然后将json
字符串值分配给命名键,如:
var dataString = JSON.stringify(dataString);
$.ajax({
type: 'POST',
url: 'update-row.php',
data: {namedKey: dataString}
success: function(itemJson) {
}
});
在服务器端,使用json_decode
解码json回到数组:
$data = filter_input(INPUT_POST, 'namedKey');
$dataArr = json_decode($data, true);