本文介绍了未捕获的SyntaxError:意外的令牌:在jquery mobile ajax调用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想用jquery mobile获取web服务,我在jquery上调用ajax调用了一个示例,我得到了这个错误Uncaught SyntaxError:Unexpected token:。我的代码在下面 < !DOCTYPE html > < html > < head > < meta charset = utf-8 / > < meta name = viewport content = width = device-width,initial-scale = 1 / > < title > webservices示例< ; / title > < link rel = 样式表 href = jquery.mobile-1.1.0.css / > < 链接 rel = stylesheet href = my.css / > < script src = https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js > < / script > < script type = text / javascript > $(document).ready(function(){ $ .ajax ({类型:GET, url:http://shoperola.com/Restaurant/foodysrest/sample, crossDomain:true, contentType:application / json; charset = utf-8, data:{}, dataType:jsonp, success:function(data){ alert(data); },错误:函数(数据){ alert(处理错误-----+ data.status); } }); }) < / script > < / head > < / html > i试图将jsonp更改为js在,然后我得到了 XMLHttpRequest无法加载http://shoperola.com/Restaurant/foodysrest/sample?{}。请求的资源上不存在Access-Control-Allow-Origin标头。原因'http://< localhost>:8088'因此不允许访问。 当我执行此代码时,我得到警告处理错误----- 200这条消息。我怎么能解决这个问题?200是成功状态消息仍然出错。我尝试在上面的ajax调用中删除crossDomain,contentType和data属性,仍然是结果是一样的。解决方案 (document).ready(function(){ .ajax({键入:GET, url:http://shoperola.com/Restaurant/foodysrest/sample, crossDomain:true, contentType:application / json; charset = utf -8,数据:{}, dataType:jsonp,成功:函数(数据){ alert(data); },错误:函数(数据){ alert(处理错误-----+ data.status); } }); }) < / script > < / head > < / html > i试图将jsonp更改为json,然后我得到了 XMLHttpRequest无法加载http://shoperola.com/Restaurant/foodysrest/sample?{}。请求的资源上没有'Access-Control-Allow-Origin'标头。来源'http: //< localhost>:8088'因此不允许访问。 当我执行此代码时,我得到警告处理错误----- 200这条消息。我如何解决这个问题? 200是成功状态消息仍然出错。我尝试在上面的ajax调用中删除crossDomain,contentType和data属性,结果仍然相同。 你的 dataType 应该是 json ,而不是 jsonp 。 但这只会消除意外的令牌错误,你还是由于CORS问题,将无法读取Web服务... I want to get the web services with jquery mobile,i wrote a sample example on ajax calling in jquery,i got this error" Uncaught SyntaxError: Unexpected token : ".My code is below<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>webservices example </title> <link rel="stylesheet" href="jquery.mobile-1.1.0.css" /> <link rel="stylesheet" href="my.css" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $.ajax({ type:"GET", url:"http://shoperola.com/Restaurant/foodysrest/sample", crossDomain: true, contentType: "application/json; charset=utf-8", data: "{}", dataType: "jsonp", success: function(data) { alert(data); }, error: function(data) { alert("Error in Processing-----" + data.status); } }); }) </script> </head> </html> i tried to change jsonp to json,then i got" XMLHttpRequest cannot load http://shoperola.com/Restaurant/foodysrest/sample?{}. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://<localhost>:8088' is therefore not allowed access".when i execute this code,I got alert with "Error in Processing-----200" this message.How can i slove this problem? 200 is success status message still getting error. I tried removing crossDomain,contentType and data attributes in the above ajax call,still the result was same. 解决方案 (document).ready(function() {.ajax({ type:"GET", url:"http://shoperola.com/Restaurant/foodysrest/sample", crossDomain: true, contentType: "application/json; charset=utf-8", data: "{}", dataType: "jsonp", success: function(data) { alert(data); }, error: function(data) { alert("Error in Processing-----" + data.status); } }); }) </script> </head> </html> i tried to change jsonp to json,then i got" XMLHttpRequest cannot load http://shoperola.com/Restaurant/foodysrest/sample?{}. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://<localhost>:8088' is therefore not allowed access".when i execute this code,I got alert with "Error in Processing-----200" this message.How can i slove this problem? 200 is success status message still getting error. I tried removing crossDomain,contentType and data attributes in the above ajax call,still the result was same.Your dataType should be json, not jsonp.But that will only remove the unexpected token error, you still will not be able to read the web service because of CORS problem... 这篇关于未捕获的SyntaxError:意外的令牌:在jquery mobile ajax调用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-16 01:03