Mui+jsonp 跨域访问Uncaught SyntaxError: Unexpected token
来源:互联网 发布:moneywiz2 mac 编辑:程序博客网 时间:2024/06/06 15:46
插件介绍:众所周知,使用ajax直接发起请求存在跨域无权限访问的问题,这时候,需要使用jsonp协议(非官方的协议)处理,jQuery中的
1、js页面
code>function login(){ var ip="http://192.168.31.6:8080/HTML_ht"; $.ajax({ type:"GET", url:ip+"/login.jsp", crossDomain: true, data:{ username:'admin', password:'123', }, dataType:'JSONP', jsonp:"callback", async:true, success:function(data){ var username = data.username; var password = data.password; if(username=="admin" && password=="123"){ alert("登陆成功"); }else{ alert("登陆失败");
2、h5页面
<code><div class="container"> <input type="text" name="username" id="username" /> <input type="password" name="password" id="password" /> <input type="button" value="Login" onclick="login()"/>
</div>
3、后台处理
public void testjson(HttpServletRequest request, HttpServletResponse response) { String callback = (String)request.getParameter("callback"); String jsonData = "{\"id\":\"3\", \"name\":"zhangsan", \"telephone\":"13612345678"}";//为了演示效果,json数据是写死的 String retStr = callback + "(" + jsonData + ")"; response.getWriter().print(retStr); }
阅读全文
0 0
- Mui+jsonp 跨域访问Uncaught SyntaxError: Unexpected token
- JSONP跨域问题报错 “Uncaught SyntaxError: Unexpected token :”
- ajax跨域访问-jsonp报错:Uncaught SyntaxError: Unexpected token":"or"<"or"{"
- jQuery-JSONP 插件跨域调用功能(Uncaught SyntaxError: Unexpected token : 出错原因解释)
- jQuery-JSONP 插件跨域调用功能(Uncaught SyntaxError: Unexpected token : 出错原因解释)
- Uncaught SyntaxError: Unexpected token <
- Uncaught SyntaxError: Unexpected token )
- Uncaught SyntaxError: Unexpected token <
- Uncaught SyntaxError: Unexpected token )
- Uncaught SyntaxError: Unexpected token )
- uncaught syntaxerror unexpected token )
- Uncaught SyntaxError: Unexpected token <
- Uncaught SyntaxError: Unexpected token <
- Uncaught SyntaxError: Unexpected token :
- Uncaught SyntaxError: Unexpected token
- Uncaught SyntaxError: Unexpected token <
- Uncaught SyntaxError: Unexpected token :
- Uncaught SyntaxError: Unexpected token )
- 支持移动端深度学习的几种开源框架
- js数组深复制和浅复制的区别
- 为什么模板不支持分离编译
- java对象的序列化和反序列化
- python播放mp3文件
- Mui+jsonp 跨域访问Uncaught SyntaxError: Unexpected token
- nginx+uwsgi+python捕获http消息并处理(一)
- 【举例】Adaboost算法的具体数学公式
- 博客导航
- ES 5.x版本的搭建。
- Java导包
- windbg调试基础
- 进程和程序的区别
- Linux 如何测试 IO 性能(磁盘读写速度)