【问题标题】:Error: jQuery ... was not called -- Ajax requesting geoJSON from Node.js cross domain server错误:jQuery ... 未被调用——Ajax 从 Node.js 跨域服务器请求 geoJSON
【发布时间】:2017-06-08 18:36:45
【问题描述】:

我正在尝试通过在一台服务器上运行的 Node.js 应用程序将 geoJSON 数据传递到在另一台服务器上运行的 Web 应用程序。我发现了很多其他与此相关的问题,但我尝试过的所有问题似乎都无法解决我的问题。

在 Chrome 上使用 RestEasy 扩展我可以毫无问题地使用我所有的 RESTapi 调用。获取、放置、删除和发布。将 url 粘贴到浏览器中也会返回带有 Chrome 控制台报告的 geoJSON 数据页面:

Resource interpreted as Document but transferred with MIME type application/json:

这是我第一次写这样的东西,我想将数据拉入客户端 web 应用程序以将 geoJSON 数据呈现到地图。

首先,我了解跨域设置需要我使用 JSONP,虽然我不熟悉我认为第一步是接收它,然后重新设计成 geojson 以便地图理解。 我将 CORS 安装到我的 Node.js 应用程序中,这似乎解决了我的跨域问题,但现在我收到了这个 jQuery 错误。

这是我的客户端 ajax 函数:

    $(document).ready(function ()
    {
        console.log("Running AJAX");
        $.ajax(
        {
            type: "GET",
            contentType: "application/jsonp; charset=utf-8",
            url: myUrl,
            cache: false,
            timeout: 5000,
            dataType: "jsonp",
            crossDomain: true,
            data: "{}",
            success: function (data)
            {
                // do my stuff
                console.log("Reading Data");
                console.log(data);
            },
            error: function (xhr, ajaxOptions, thrownError)
            {
                console.log("http Status Response: " + xhr.status);
                console.log(thrownError);
            }
        });
    });

这是我在服务器上的 Node.js 应用:

app.get('/api/objects', function(req, res)
{
    Object.getObjects(function(err, objects)
    {
        if (err)
        { 
            res.json(err);
        } 

        res.jsonp(objects); 
    });
});

这是来自 Chrome 控制台的错误:

http Status Response: 200
Error: jQuery31108564601072970404_1485231436558 was not called
at Function.error (jquery.min.js:2)
at b.converters.script json (jquery.min.js:4)
at Nb (jquery.min.js:4)
at A (jquery.min.js:4)
at HTMLScriptElement.c (jquery.min.js:4)
at HTMLScriptElement.dispatch (jquery.min.js:3)
at HTMLScriptElement.q.handle (jquery.min.js:3)

【问题讨论】:

    标签: jquery json ajax node.js


    【解决方案1】:

    发现问题。 事实证明,重新启动 apache(运行 node.js 应用程序的服务器)不会重新启动 node.js 应用程序。 所以我在服务器上的更改从未被应用。

    这是重新启动 node.js 应用程序后控制台现在读取的内容。经验教训。

    Reading Data
    Array[16]
    0: Object__v: 0_id: "58815cd0110dcc3b1e51d411"geometry: Objectproperties: Objecttype: "Feature"__proto__: 
    Object1: 
    Object2: 
    Object3: 
    Object4: 
    Object5: 
    Object6:
    Object7: 
    Object8: 
    Object9: 
    Object10: 
    Object11: 
    Object12: 
    Object13: 
    Object14: 
    Object15: 
    Object
    length: 16
    __proto__: Array[0]
    

    【讨论】:

      猜你喜欢
      • 2013-09-23
      • 2015-06-08
      • 2013-12-14
      • 2015-05-05
      • 2017-06-06
      • 2012-04-23
      • 2014-03-04
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多