我有这段代码:
function Save(whichOne){
var name = $('#name').val();
var surname = $('#surname').val();
$.ajax({
url: 'SaveEntry.php',
type: 'post',
data: { "callFunc1": whichOne},
success: function(response) {
alert(response);
}
});
}
我想做这样的事情:
function Save(whichOne){
var name = $('#name').val();
var surname = $('#surname').val();
$.ajax({
url: 'SaveEntry.php',
type: 'post',
data: { "callFunc1": {whichOne, name, surname}},
success: function(response) {
alert(response);
}
});
}
但它不起作用。问题出在这一行:
data: { "callFunc1": {whichOne, name, surname}},
如何发布多个值?
编辑: 我收到此错误: 警告:缺少func1()
的参数2我有这段代码:
if (isset($_POST['callFunc1'])) {
echo func1($_POST['callFunc1']);
}
答案 0 :(得分:4)
除非您想发送JSON数据,否则您需要键值对:
data: { "callFunc1": whichOne, "name": name, "surname":surname}
答案 1 :(得分:0)
取决于您想要传递的内容。它是
data: [whichOne, name, surname]
- 这将是一个数组
或它是一个对象
data: {
"whichOne" : whichOne,
"name" : name,
"surname" : surname
}