doupin5408 2013-08-07 21:55
浏览 50
已采纳

SyntaxError:意外的令牌S.

I'm stumped. I'm doing a simple ajax form where the user will enter data and it will send the data to the server.

I've got the following code:

<?php
require("/mnt/library/configdb.php");        
require("/mnt/library/accessdb.php");

db_config_utility();
db_connect();

//Assign passed parameters
$submitDate = $_POST['submitDate'];
$mname      = $_POST['mname'];
$mid        = $_POST['mid'];
$coffice    = $_POST['coffice'];
$street     = $_POST['street'];
$city       = $_POST['city'];
$state      = $_POST['state'];
$zipcode    = $_POST['zipcode'];
$lat        = $_POST['lat'];
$lng        = $_POST['lng'];

//Setting up sql call
$sql="INSERT INTO manholes(
    submit_date,
    manhole_name, 
    manhole_id, 
    central_office, 
    street,
    city,
    state,
    zipcode,
    latitude,
    longitude
    )
    VALUES (
    '$submitDate',
    '$mname',
    '$mid',
    '$coffice',
    '$street',
    '$city',
    '$state',
    '$zipcode',
    '$lat',
    '$lng'
    )";

    echo("SQL: " . $sql);

//Making sql calls
mysql_query($sql);
?>

The data is getting to the server correctly as the echo prints out correctly. The server sends back a code 200 but does not place the data into the database. It also causes my ajax post to fall into the error function where the "SyntaxError: Unexpected token S".

If I remove the echo then the error thrown is "SyntaxError: Unexpected end of input"

Any advice on how to find what is causing the problem?

  • 写回答

1条回答 默认 最新

  • duanchoupo1104 2013-08-07 21:59
    关注

    The unexpected token S is probably because you're echoing text, which your ajax isn't expecting as a response. Removing it causes the other error because then you're not sending ANYTHING. You should check to see what your ajax function expects to receive (JSON?) and, after running your query, echo the correct response so your ajax knows it was successful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?