发送ajax请求不起作用

发送ajax请求不起作用,ajax,mongodb,jquery,curl,Ajax,Mongodb,Jquery,Curl,我发送以下curl请求以从mongodb获得结果 curl --data 'cmd={"geoNear" : "items", "near":[6.8590845,79.9800719]}' 'http://82.196.xxx.xxx:27080/weather/_cmd' 它正在工作。我尝试发送ajax请求来执行上述curl请求 $.ajax({ url: 'http://82.196.xxx.xxx:27080/weather/_cmd',

我发送以下curl请求以从mongodb获得结果

curl --data 'cmd={"geoNear" : "items", "near":[6.8590845,79.9800719]}' 'http://82.196.xxx.xxx:27080/weather/_cmd'
它正在工作。我尝试发送ajax请求来执行上述curl请求

         $.ajax({
            url: 'http://82.196.xxx.xxx:27080/weather/_cmd',
            type: 'POST',
            // dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
            data: {"geoNear" : "items", "near":[6.8590845,79.9800719]},
        })
        .done(function() {
            console.log("success");
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {
            console.log("complete");
        });
我认为问题在于我的数据对象。curl请求具有
'cmd={“geoNear”:“items”,“near”:[6.8590845,79.9800719]}
。但我不知道它如何转换为ajax请求

         $.ajax({
            url: 'http://82.196.xxx.xxx:27080/weather/_cmd',
            type: 'POST',
            // dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
            data: {"geoNear" : "items", "near":[6.8590845,79.9800719]},
        })
        .done(function() {
            console.log("success");
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {
            console.log("complete");
        });
但它不起作用。我得到了
200 OK
状态。请帮帮我

 $.ajax({
    url: '/weather/_cmd',
    type:'POST',
    dataType: 'json',
    crossDomain : true,
    data: {
        cmd: JSON.stringify({
            "geoNear" : "items",
            "near": [6.8590845,79.9800719]
        })
    },
    success: function(res) {
        //do stuff with res
    }
});

ProxyPass /weather http://82.196.11.207:27080/weather/_cmd
ProxyPassReverse /weather http://82.196.11.207:27080/weather/_cmd
将上述代理传递添加到Apache中,然后尝试此操作。它会起作用的。问题是您无法使用jsonp传递POST请求。mongo我们需要POST请求。这是一种方法我测试了它,对我来说效果很好

-更新-它不接受json,您必须将其作为字符串传递

将上述代理传递添加到Apache中,然后尝试此操作。它会起作用的。问题是您无法使用jsonp传递POST请求。mongo我们需要POST请求。这是一种方法我测试了它,对我来说效果很好


-更新-它不接受json,您必须将其作为字符串传递

这不是我的问题。我得了200分。但是我没有收到成功消息。请尝试
data:{cmd:JSON.stringify({“geoNear”:“items”,“near”:[6.8590845,79.9800719]})
看起来服务器需要一个名为
cmd
的参数,作为值的JSON字符串也会更改
fail
登录到
console.log(“error”,arguments)data:{cmd:JSON.stringify({“geoNear”:“items”,“near”:[6.8590845,79.9800719]})
看起来服务器需要一个名为
cmd
的参数,作为值的JSON字符串也会更改
fail
登录到
console.log(“error”,arguments)