google在jquery ajax调用中放置api错误。。。html\u属性

google在jquery ajax调用中放置api错误。。。html\u属性,api,jquery,Api,Jquery,我将新的GooglePlacesAPI与jquery/ajax一起使用。当我运行此代码时: $.ajax({ url: "https://maps.googleapis.com/maps/api/place/search/json?location=40.7834345,-73.9662495&radius=50&sensor=false&key=Your_API_KEY_HERE", dataType: "jsonp", data: { name: 'rogue

我将新的GooglePlacesAPI与jquery/ajax一起使用。当我运行此代码时:

$.ajax({
url: "https://maps.googleapis.com/maps/api/place/search/json?location=40.7834345,-73.9662495&radius=50&sensor=false&key=Your_API_KEY_HERE",
dataType: "jsonp",
data: {
    name: 'rogue'
},
success: function( data ) {
     console.log(data)
}
});

我得到这个错误:无效的标签html_属性[];我认为这妨碍了我在控制台中看到输出对象,尽管我可以在firebug的json选项卡中看到响应,但似乎PlacesAPI到目前为止还不支持ajax

服务器用正确的JSON响应是不够的应答服务器必须支持JSONP,并使用jQuery生成的回调来包围JSON应答。响应必须如下所示:

jQuery17101705844928510487_1324249734338({"data":"whatever"});
JSONP所做的攻击是将响应解释为脚本,因为脚本标记不受同源策略的影响。如果没有回调,您就没有机会在浏览器中执行此操作

如果不支持,您必须执行服务器的请求。

使用PHP的服务器示例:

<?php
header("Content-Type:text/javascript"); // avoid browser warnings
$request = new HttpRequest("http://programmingisart.com/json-data-source.php", HttpRequest::METH_GET);
$request->send();
$json_data = $request->getResponseBody();

// wrap the data as with the callback
$callback = isset($_GET["callback"]) ? $_GET["callback"] : "alert";
echo $callback."(".$json_data.");";

到目前为止,PlacesAPI似乎还不支持ajax

服务器用正确的JSON响应是不够的应答服务器必须支持JSONP,并使用jQuery生成的回调来包围JSON应答。响应必须如下所示:

jQuery17101705844928510487_1324249734338({"data":"whatever"});
JSONP所做的攻击是将响应解释为脚本,因为脚本标记不受同源策略的影响。如果没有回调,您就没有机会在浏览器中执行此操作

如果不支持,您必须执行服务器的请求。

使用PHP的服务器示例:

<?php
header("Content-Type:text/javascript"); // avoid browser warnings
$request = new HttpRequest("http://programmingisart.com/json-data-source.php", HttpRequest::METH_GET);
$request->send();
$json_data = $request->getResponseBody();

// wrap the data as with the callback
$callback = isset($_GET["callback"]) ? $_GET["callback"] : "alert";
echo $callback."(".$json_data.");";

也许数据类型应该是json,因为假设jsonpI不认为这可以工作,因为google和我的服务器是两个不同的域。。。。所以你必须要做的是,jsonpmaybe数据类型应该是json,因为假设jsonpI不认为这可以工作,因为google和我的服务器是两个不同的域。。。。因此,您必须执行JSONP。您能解释一下第一个示例中是什么,第二个示例中是什么json-wrapper.php吗?Google API url在这些代码示例中的位置如何?您能否解释一下第一个示例中的内容以及第二个示例中的json-wrapper.php是什么?GoogleAPI url在哪里适合这些代码示例?