我有这段代码:
var name= "theName";
var surname= $('#surname').val();
$.ajax({
url: 'SaveEdit.php',
type: 'post',
data: { "callFunc1": whichOne},
success: function(response) {
alert(response);
}
});
它正在运作,但我需要做这样的事情:
var name= "theName";
var surname= $('#surname').val();
$.ajax({
url: 'SaveEdit.php',
type: 'post',
data: { "callFunc1": whichOne, name},
success: function(response) {
alert(response);
}
});
它给我的错误如下:
警告:缺少func1()
我也在使用这段代码:
function func1($data, $name){
//some code here
}
if (isset($_POST['callFunc1'])) {
echo func1($_POST['callFunc1']);
}
如何正确做到?
答案 0 :(得分:2)
创建一个数组并传递所需的变量。否则试试这个: -
var name= "theName";
var surname= $('#surname').val();
$.ajax({
url: 'SaveEdit.php',
type: 'post',
data: { "callFunc1": whichOne,"callFunc2": name},
success: function(response) {
alert(response);
}
});
答案 1 :(得分:0)
您应该在AJAX调用中为secund参数添加名称。别忘了将它传递给你的函数“func1”。
示例:
if (isset($_POST['callFunc1'])) {
echo func1($_POST['callFunc1'], $_POST['callFunc2']);
}