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.

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

报告相同问题?

悬赏问题

  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案