duanlao6573 2014-03-08 14:16
浏览 64

Ajax错误和Uncaught SyntaxError:意外的令牌错误

I know there has been a thousand topics on this error, but none seem to match my issue. The usual answers appear to be invalid json or a problem with the datatypes in the ajax call. All json I send back is from php's json_encode.

My problem seems to be a bit weirder:

I am creating an application and this runs perfectly fine on the server at work (windows server 2008, IIS 7, PHP 5.3), and even locally on a work pc using WAMP, and on my home server which is windows 7 with IIS 7 and PHP 5.4.

However, recently when copying my application over from work to home (via Dropbox - no code changes whatsoever), suddenly every single ajax call made by jQuery is not working correctly... but it also does;

  • using console.log(data) I can see that what is being returned is exactly what should be.
  • but any if statement etc doesn't recognise the value

For example, my login script echos true from php (interpreted by JS as '1') if logged in, and I can see this 1 being sent back with console.log - but JS then doesn't recognise this when I use (data == 1) or data == '1', I'm baffled as to how JS can recognise data in console.log, but not in an if statement on the next line.

I get this same problem for absolutely any ajax call on any page of the application, whether JSON.parse, $.parseJSON or just standard post is being used to decipher the return value. I have also tried using dataType json for these calls with no success. When I do try using json datatype I get 'Uncaught SyntaxError: Unexpected token', but no errors at all for standard post and post backs. All calls work perfectly on the work server.

Here is the ajax success of my login call:

success: function(data) {
console.log(data);
if (data == 1) {
window.location = (window.lasturl == "" ? "index.php" : window.lasturl);
} else {
$form.after('failed to login, username and password may be incorrect - please try again');
}

Where $form is set to the login form.

console.log shows: 1 but the data == 1 if statement is not performed, and the else statement is.

It's doing my head in!

Any ideas?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据