我不能让我的JSON请求工作

I can't get my JSON request to work

本文关键字:请求 工作 JSON 我的 不能      更新时间:2023-09-26

我已经创建了一个url,我需要传递给警察数据API。

var api_url="http://policeapi2.rkh.co.uk/api/locate-neighbourhood?q="+latlon;
document.write(api_url);

当您手动将URL输入浏览器时,URL可以工作,但我需要一些JavaScript来发送API请求并将其吐槽到页面上。我的JavaScript是好的,但我没有jQuery的知识。

提前谢谢大家,聪明的朋友们,请保持简单。

试试下面的…它起作用了JS Fiddle http://jsfiddle.net/9AZyZ/

function abc(latLong){
     $.ajax({
                    url: 'http://query.yahooapis.com/v1/public/yql',
                        data: {
                            q: "select * from json where url ='http://policeapi2.rkh.co.uk/api/locate-neighbourhood?q="+latLong+"'",
                            format: "json"
                        },
                        dataType: "jsonp",
                    success: function (data) {
                        alert(JSON.stringify(data));

                    },
                    error: function (result) {
                        alert("Sorry no data found.");
                    }
                });
}