-1

我从 firebug 收到以下语法错误:

SyntaxError: missing ) 在参数列表之后

 $.ajax({    //create an ajax request to load_page.php
    type: "POST",
    url: "display.php",
    data:{faculties:faculty},            
    dataType: "json",   //expect json to be returned                
    success: function(response)
    {                    

        $.each(response,function(i,item)
        {
            $("table tbody").append("<tr><td>"+response[i].code+"</td>"+"<td>"+response[i].title"</td>"+"<td>"+response[i].lecturer"</td"+"<td>"+response[i].description"</td></tr>"); 
            // The line above is giving me the 
            // syntax error , i cant figure out what's wrong                                
        }); 
    }
});

这是 PHP 脚本传递的 JSON 对象 $data[]=array("code"=>$code,"title"=>$title,"lecturer"=>$lecturer,"description"=>$description);

我花了 1 小时调试,但找不到语法错误。你们能帮帮我吗?

4

4 回答 4

3

代替

$("table tbody").append("<tr><td>"+response[i].code+"</td>"+"<td>"+response[i].title"</td>"+"<td>"+response[i].lecturer"</td"+"<td>"+response[i].description"</td></tr>"); 

$("table tbody").append("<tr><td>"+response[i].code+"</td>"+"<td>"+response[i].title+"</td>"+"<td>"+response[i].lecturer+"</td>"+"<td>"+response[i].description+"</td></tr>");  

你的连接是错误的。使用一个好的编辑器来跟踪。

于 2013-09-05T06:31:28.097 回答
2

你没有关闭你的td标签。

"+response[i].lecturer+"</td"+"<td>"+
---------------------------^^------

用下面的代码替换您的代码

$("table tbody").append("<tr><td>"+
    response[i].code+
    "</td><td>"+
    response[i].title+
    "</td><td>"+
    response[i].lecturer+
    "</td><td>"+response[i].description+
    "</td></tr>"
); 
于 2013-09-05T06:33:48.453 回答
0

你能用这个吗

替换此代码

      $.ajax({ //create an ajax request to load_page.php
             type: "POST",
             url: "display.php",
             data: {
                   faculties: faculty
             },
            dataType: "json", //expect json to be returned                
            success: function (response) {

            $.each(response, function (i, item) {
                          $("table tbody").append("<tr><td>" + response[i].code + "</td><td>" + response[i].title + "</td><td>" + response[i].lecturer + "</td><td>" + response[i].description + "</td></tr>");
                         //The line above is giving me the syntax error , i cant figure out whtas wrong


           });

           }

    });
于 2013-09-05T06:37:20.827 回答
0

在您的代码中替换它

$.each(response,function(i,item)
{
$("table tbody").append("<tr><td>"+response[i].code+"</td>"+"<td>"+response[i].title"</td>"+"<td>"+response[i].lecturer"</td>"+"<td>"+response[i].description"</td></tr>");
});
于 2013-09-05T07:11:17.083 回答