使用jquery-ajax执行curl命令

Las*_*ama 5 jquery json curl jsonp

我使用以下输入执行curl命令到mongoDB.

curl --data 'cmd={"geoNear" : "items", "near":[6.8590845,79.9800719]}' 'http://72.123.xxx.xxx:27080/weather/_cmd'
Run Code Online (Sandbox Code Playgroud)

我想用jsonp或json执行它并获得响应.我在jsonp请求下面尝试过.

var url =  "http://72.123.xxx.xxx:27080/weather/_cmd";
$.getJSON(url + "?callback=?",
    {
        cmd:{"geoNear" : "items", "near": 6.8590845,79.9800719]}
    },
    function(tweets) { }
);
Run Code Online (Sandbox Code Playgroud)

我从控制台得到了什么.请帮我解决一下这个.谢谢.

Las*_*ama 5

最后,我想出了解决方案.

$.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://72.123.xxx.xxx:27080/weather/_cmd
ProxyPassReverse /weather http://72.123.xxx.xxx:27080/weather/_cmd
Run Code Online (Sandbox Code Playgroud)

将以上代理传递添加到您的Apache并尝试此操作.它会工作.问题是你不能通过使用jsonp传递POST请求.我们需要POST请求.这是一种方法.:D我测试了它并且对我来说非常适合.它不会接受json,你必须将它作为字符串传递.