前台的一个页面的ajax如下
function test(operation,rowno)
{
var name=$('#Start tr').eq(rowno).children('td').eq(1).text();
alert("operation:"+operation);
alert("name:"+name);
$.ajax({
type:'GET',
url:'server.php?operation='+operation+'&name='+name,
async:true,
success:function(response){
alert(response);
},
error:function(xhr,r,e){
}
});
}
后台页面server.php代码如下
<?php
$operation=$_GET('operation');
$name=$_GET('name');
echo 'success';
?>
我这么写有什么错误呢?为什么报错“Function name must be a string in server.php”求解
应该这样写后台
<?php
$operation=$_GET['operation'];
$name=$_GET['name'];
if($operation && $name) echo 'success';
?>
错误的原因是:
$_GET('name')这样写毕态迟的话,php首先认为你的get()是一个function,
但是前面又有$符号,这在php中他又认为这是一个变量,
但是变量是不能作为一个function的,所以抛出错误手李Function name must be a string
$_GET['xxx']是其闭举他系统变量都是用的方括号而非括弧,这点要注意下(例如 $_POST['xxx'],$_FILE['xxx']等等)
php中,访问数组元素是方括号,而不是圆括号