jQuery.ajax()V1.5返回" parsererror"对于JSON数据 [英] jQuery.ajax() v1.5 returns "parsererror" for json data

查看:97
本文介绍了jQuery.ajax()V1.5返回" parsererror"对于JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的功能,从列表中得到一个服务器ID。该函数总是返回parsererror。我已经看过了返回的JSON数据,但我似乎无法得到它的工作,因为jQuery的改写在V1.5阿贾克斯。

I have this function for getting a server id from a list. The function always returns "parsererror". I have looked at the JSON data returned but I cant seem to get it working, since jQuery have rewritten the ajax in v1.5.

function server_id()
{
    $.ajax({
        type: "GET",
        url: "http://localhost/server_list.php",
        dataType: "json", 
        success: function(data, status) {
             alert(status + "\n\n" + data.server_id);
        },
        complete: function(data, status){
                  alert(status);
        }
    });

}

server_list.php

server_list.php

    header('Content-type: application/json');

    $output['server_id'] = '123';
    print json_encode($output);

在萤火网>> XHR它把它读成JSON,因为它带来了选项卡和响应选项卡显示下面是什么。

In firebug Net >> XHR it reads it as JSON as it brings up the tab and the Response tab shows what is below.

{"server_id":"123"}

我自己也尝试设置内容类型头象下面,但有没有运气。

I have also tried setting the content type header like below but having no luck.

Content-type: application/json

更新时间:

我只得到parsererror如果验证插件加载从<一个href="http://bassistance.de/jquery-plugins/jquery-plugin-validation">http://bassistance.de/jquery-plugins/jquery-plugin-validation docs.jquery.com/Plugins/Validation V1.7。

I only get "parsererror" if the validation plugin is loaded from http://bassistance.de/jquery-plugins/jquery-plugin-validation docs.jquery.com/Plugins/Validation v1.7.

如果您添加的jQuery插件会自动添加JSONP回调,即使你设置为虚假或不包括PARMS为JSONP查询字符串。很奇怪

If you add the plug jquery automatically adds the jsonp callback to the query string even when you set to false or dont include the parms for jsonp. Very Strange

在如何解决任何想法?

感谢

推荐答案

您似乎想定期JSON通信(的dataType 是JSON,而不是JSONP和 server_list.php 发送JSON),但你设定 JSONP 选项。删除 JSONP jsonpcallback 行。设置 JSONP 并不意味着你禁用它!

You seem to want regular json communication (dataType is "json" instead of "jsonp" and server_list.php sends json), but you're setting jsonp options. Remove the jsonp and jsonpcallback lines. Setting jsonp to false does not mean you disable it!

在这两条线被注释掉,一切似乎很好地工作

When these two lines are commented out, everything seems to work fine.

这篇关于jQuery.ajax()V1.5返回&QUOT; parsererror&QUOT;对于JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆