this is my code:

这是我的代码:

$(function() {

   $.ajax({
    url:'http://localhost:3000/business_places',
    type:'GET',
    dataType:'jsonp',
    done: function(data){
        alert(1)

    },
    error: function(data) {
        alert(2)
    },
    success: function(data) {
        alert(3);
    }

});


});

No matter what I try I leep getting the alert(2), but when I check the status in data I see success.

无论我尝试什么,我都会听到警报(2),但是当我检查数据中的状态时,我看到了成功。

The request is to a nodejs server. It sends as a response a json object like this:

请求是nodejs服务器。它作为响应发送一个像这样的json对象:

exports.getBusinessPlaces = function(req, res) {
console.log('Retrieving business places: ');

db.collection(BUSINESS_PLACE_COLLECTION, function(err, collection) {
    collection.find().toArray(function(err, items) {
        // var j = {a:items};
        res.send(items);
    });
});
};

The json itself starts and ends with [] because its an array. I tried putting in inside another json so it would look like a standards json : {a:items} but this didn't work either.

json本身以[]开头和结尾,因为它是一个数组。我尝试将其放入另一个json中,因此它看起来像标准json:{a:items}但这也不起作用。

The ajax call is now being made from another local web server (I started with a local html file but moved to a web server because I though this might be the problem).

ajax调用现在是从另一个本地Web服务器进行的(我开始使用本地html文件但是移动到Web服务器,因为我可能会遇到这个问题)。

Also added in node a allow-cross-origin header.

还在节点中添加了允许跨源头。

I'm clueless.

1 个解决方案

#1


1

Change dataType:'jsonp' to dataType:'json'

将dataType:'jsonp'更改为dataType:'json'

See the answer to this question

看到这个问题的答案

更多相关文章

  1. JQuery.AJAX - 我的服务器可以返回一大块数据吗?
  2. jQuery向服务器请求数据并处理
  3. 如何使用XMLHttpRequest向服务器发送数组
  4. 使用js和ajax从django服务器检索数据
  5. 使用jQuery.ajax post函数将javascript数组中的数据传递给服务器
  6. ASP.NET下使用jQuery UI下的Dialog,服务器端按钮无响应的问题。
  7. Jquery注册服务器控件事件与判断控件的值
  8. 与symfony一起使用ajax时出现500内部服务器错误
  9. Ajax技术--服务器返回数据格式(HTML,XML,JSON)

随机推荐

  1. Visual Studio 跨平台开发实战(4) - Xama
  2. Android系统启动分析
  3. Android中LCD背光驱动
  4. android:组件化方案
  5. Android 性能分析案例
  6. Qt on Android:怎样适应不同的屏幕尺寸
  7. android控件的对齐方式详解
  8. android沉浸状态栏实现、地图多线路规划
  9. android初窥
  10. Android(安卓)资源简介(五) AnimationDrawa