【发布时间】:2016-10-19 03:06:22
【问题描述】:
好的,在我上一个问题之前,我已经尝试对我的代码进行一些修改,但不知何故我仍然落后。
这是我创建的 jquery
$(document).ready(function()
{
var array_ids = [];
$('.add').click(function()
{
array_ids.push($(this).parent().siblings('.row_id').html().trim());
alert(array_ids);
});
$('.show').click(function(e)
{
//e.preventDefault();
var jsonString = JSON.stringify(array_ids);
$.ajax(
{
method: 'POST',
url: 'addsale.php',
data: {data : jsonString},
cache: false,
dataType: "json",
success: function()
{
console.log(data.reply);
alert(data.reply);
}
});
});
});
还有addsale.php
if(isset($_POST['push'])) //tried it commenting also!
{
$data = array();
$data = json_decode(stripslashes($_POST['data']));
foreach($data as $d){
echo $d;
}
}
谁能告诉我访问数组和从addsale.php获取html到当前页面缺少什么?
【问题讨论】:
-
使用
$_POST['data'] -
$data = $_POST['data'];这东西??
-
您的
$.ajax()成功回调使用了一个未定义的变量data(您可能希望它声明为success: function(data) { ...)。
标签: javascript php jquery