Javascript 未捕获的SyntaxError:意外标记:在chrome和“上”;语法错误:缺少;“在声明之前”;在firefox上
我的代码是:Javascript 未捕获的SyntaxError:意外标记:在chrome和“上”;语法错误:缺少;“在声明之前”;在firefox上,javascript,jquery,ajax,Javascript,Jquery,Ajax,我的代码是: function getCategoryResponse() { var appid = "1"; $.ajax({ type: 'GET', url: 'http://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/genres?id=36&callback=myCallbackFunction', data: {}, dataType:
function getCategoryResponse() {
var appid = "1";
$.ajax({
type: 'GET',
url: 'http://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/genres?id=36&callback=myCallbackFunction',
data: {},
dataType: 'jsonp',
success: function (data) {
var appData = data.results[0]; //get first record from array
console.log(appData);
return;
},
error: function () {
//alert('something bad happened');
console.log("something bad happened");
}
});
}
其结果是:
"Uncaught SyntaxError: Unexpected token :" /* on chrome */
"SyntaxError: missing ; before statement" /* on firefox */
该URL不返回JSONP响应,只返回如下启动的JSON响应:
{
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
myCallbackFunction({
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
您必须查阅文档,了解如何告诉它您需要JSONP,它的开头是这样的:
{
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
myCallbackFunction({
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
另外:在使用jQuery时,最好允许jQuery指定回调函数的名称,而不是自己指定。该URL不返回JSONP响应,只返回如下启动的JSON响应:
{
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
myCallbackFunction({
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
您必须查阅文档,了解如何告诉它您需要JSONP,它的开头是这样的:
{
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
myCallbackFunction({
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
另外:在使用jQuery时,最好允许jQuery指定回调函数的名称,而不是自己指定。该URL不返回JSONP响应,只返回如下启动的JSON响应:
{
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
myCallbackFunction({
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
您必须查阅文档,了解如何告诉它您需要JSONP,它的开头是这样的:
{
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
myCallbackFunction({
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
另外:在使用jQuery时,最好允许jQuery指定回调函数的名称,而不是自己指定。该URL不返回JSONP响应,只返回如下启动的JSON响应:
{
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
myCallbackFunction({
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
您必须查阅文档,了解如何告诉它您需要JSONP,它的开头是这样的:
{
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
myCallbackFunction({
"36": {
"name": "App Store",
"id": "36",
"url": "https://itunes.apple.com/us/genre/ios/id36?mt=8",
"rssUrls": {
"topAppsByRevenue": "https://itunes.apple.com/us/rss/topappsbyrevenue/genre=36/json",
"topPaidIpadApplications": "https://itunes.apple.com/us/rss/toppaidipadapplications/genre=36/json",
"topIpadAppsByRevenue": "https://itunes.apple.com/us/rss/topipadappsbyrevenue/genre=36/json",
"topFreeIpadApplications": "https://itunes.apple.com/us/rss/topfreeipadapplications/genre=36/json",
单独:使用jQuery时,最好允许jQuery指定回调函数的名称,而不是自己指定。在寻求帮助时,请保持礼貌,并使用合理的,一致缩进。尝试使用检查语法感谢共享检查语法的链接。请求帮助时,请保持礼貌,并使用合理、一致的缩进设置代码格式。尝试使用检查语法感谢共享检查语法的链接。请求帮助时,请保持礼貌,使用合理、一致的缩进设置代码格式。尝试使用检查语法感谢分享检查语法的链接。寻求帮助时,请保持礼貌,使用合理的缩进设置代码格式,一致的缩进。请尝试使用检查语法感谢您共享用于检查语法的链接。当我使用onlu json时,如:url:“”,数据:{},数据类型:'json',其给定错误如:XMLHttpRequest无法加载。请求的资源上不存在“Access Control Allow Origin”标头。因此不允许访问源“null”。我是JavaScript新手:请帮助我分析此URL:Thanks@NaeemParacha:是的,使用
dataType:'json'
时出现错误的原因是,然后您使用的是普通的XMLHttpRequest,而这些请求由。您使用JSONP可能是对的,您只需要查阅正在使用的Apple API的文档,了解如何告诉它您需要JSONP响应。(假设它支持JSONP。)与此URL相同的代码工作正常。。url:''@naemparacha:我告诉过你:告诉API你需要JSONP,而不是JSON。当我使用onlu JSON时,比如:url:'',数据:{},数据类型:'JSON',它的给定错误是:XMLHttpRequest无法加载。请求的资源上不存在“Access Control Allow Origin”标头。因此不允许访问源“null”。我是JavaScript新手:请帮助我分析此URL:Thanks@NaeemParacha:是的,使用dataType:'json'
时出现错误的原因是,然后您使用的是普通的XMLHttpRequest,而这些请求由。您使用JSONP可能是对的,您只需要查阅正在使用的Apple API的文档,了解如何告诉它您需要JSONP响应。(假设它支持JSONP。)与此URL相同的代码工作正常。。url:''@naemparacha:我告诉过你:告诉API你需要JSONP,而不是JSON。当我使用onlu JSON时,比如:url:'',数据:{},数据类型:'JSON',它的给定错误是:XMLHttpRequest无法加载。请求的资源上不存在“Access Control Allow Origin”标头。因此不允许访问源“null”。我是JavaScript新手:请帮助我分析此URL:Thanks@NaeemParacha:是的,使用dataType:'json'
时出现错误的原因是,然后您使用的是普通的XMLHttpRequest,而这些请求由。您使用JSONP可能是对的,您只需要查阅正在使用的Apple API的文档,了解如何告诉它您需要JSONP响应。(假设它支持JSONP。)与此URL相同的代码工作正常。。url:''@naemparacha:我告诉过你:告诉API你需要JSONP,而不是JSON。当我使用onlu JSON时,比如:url:'',数据:{},数据类型:'JSON',它的给定错误是:XMLHttpRequest无法加载。请求的资源上不存在“Access Control Allow Origin”标头。因此不允许访问源“null”。我是JavaScript新手:请帮助我分析此URL:Thanks@NaeemParacha:是的,使用dataType:'json'
时出现错误的原因是,然后您使用的是普通的XMLHttpRequest,而这些请求由。您使用JSONP可能是对的,您只需要查阅正在使用的Apple API的文档,了解如何告诉它您需要JSONP响应。(假设它支持JSONP。)与此URL相同的代码工作正常。。url:''@NaeemParacha:我告诉过你:告诉API你需要JSONP,而不是JSON。