返回有效JSON时触发getJSON失败(即使在同一域上)


getJSON fail being triggered (even on same domain) when valid JSON is returned

使用PHP和jQuery的一个非常简单的示例存在一些问题。

PHP文件

<?php
// This is where we return all of our initial widget markup
header('Content-Type: application/json');
$markup = array('markup' => 'No markup here');
echo json_encode($markup);
<<p> JS函数/strong>
    jQuery(document).ready(function($) {
        var widgetURL = "http://samedomain.com/vip/php/markup.php?callback=?";
        $.getJSON(widgetURL, {
            format: "json"
        }).done(function( data ) {
            console.log('Success!')
        }).fail(function (data) {
           console.log('Failed!');
        });
    });

然而每次失败。尽管检查JSON显示它在响应中是有效的。例如,头说200OK,并列出我的有效JSON。

合法的JSON返回200 OK响应 {"markup":"No markup here"}

那么为什么函数失败呢?

看起来是同一个域名的原因!挑剔的Javascript。;)

这是完整的解释。谢谢大家的帮助。

见getJSON失败,JSON验证