任何人都可以帮助我在jquery中捕获语法错误

时间:2013-06-21 01:06:50

标签: php ajax json

在我的控制台中,我在第10行遇到语法错误。我无法弄清楚我的代码有什么问题。非常感谢你的帮助。

$(document).ready(function () { 
    // Skill sort on change 
    $('#order_by').on('change', function(){ 
        $.ajax({ 
            type: "POST", 
            url: "sort_skill_be.php", 
            dataType: "json", 
            data: { skill: this.value }, 
            error: function (qXHR, textStatus, errorThrown) { 
                console.log(errorThrown);  // SYNTAX ERROR HERE
            }, 
            success: function (result) { 
                alert(result[0].skill); 
                alert('i got here'); 
            } 
        }); 
    }); 
});

ERROR MSG SyntaxError {}

非常感谢你的帮助和帮助。

当我提醒错误时,我得到SyntaxError: Unexpected end of input

EDIT 服务器端代码

<?php
session_start();
include 'database.php';
$skill_sort = $_POST['skill'];
sortSkill($skill_sort);
?>


function sortSkill($skill){
    // If All skill is selected display posts normally
    if ($skill == 'All'){
        displayPosts();
        exit;
    }
    $db = connect();
    $sql = "SELECT * FROM users LEFT JOIN posts 
            ON users.idUsers = posts.fkuser 
            WHERE posts.fkuser IS NOT NULL and users.skill=:skill
            ORDER BY date DESC";
    $stmt = $db->prepare($sql);
    $stmt->execute(array(':skill' => $skill));      
    if ($stmt->rowCount() == 0){
        // Nothing has returned
        unset($_SESSION['recent_posts']); // Reset session of posts if no posts appear.
    } 
    else
    {
        $recent_posts = helpFetchPostInfo($stmt);
        return $recent_posts;
    }
}




 // IS THIS CORRECT??
function helpFetchPostInfo($stmt){
    $results = $stmt->fetchAll();
    $recent_posts = array();
    foreach ($results as $row){
        $post = array(
            'username' => $row['username'],
            'steam' => $row['steam'],
            'skill' => $row['skill'],
            'description' => $row['description'],
            'date' => $row['date'],
        );
        array_push($recent_posts, $post);
    }
    return json_encode($recent_posts); 
}

?>

来自浏览器的标题/网络

Request URL:http://zeex/sort_skill_be.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:10
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:PHPSESSID=9db38628119ef72c7be1c20eaa5da13d
Host:zeex
Origin:http://zeex
Referer:http://zeex/index.php
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
skill:High
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Length:0
Content-Type:text/html
Date:Fri, 21 Jun 2013 01:40:15 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=97
Pragma:no-cache
Server:Apache
X-Powered-By:PHP/5.4.4

0 个答案:

没有答案