Jquery ajax 跨域
来源:互联网 发布:crm软件有哪些 编辑:程序博客网 时间:2024/05/01 08:55
服务器端代码:IP:10.11.18.154
package main;import java.io.IOException;import java.io.PrintWriter;import java.net.URLDecoder;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class UserLogin extends HttpServlet{private static final long serialVersionUID = 1L;private void processRequest(HttpServletRequest request,HttpServletResponse response)throws ServletException , IOException{response.setContentType("text/html;charset=UTF-8");PrintWriter out = response.getWriter();try{String name = request.getParameter("UserAcc");String pass = request.getParameter("Passwd");String UserAcc = URLDecoder.decode(name,"UTF-8");String Passwd = URLDecoder.decode(pass,"UTF-8");System.out.println(UserAcc+"=="+Passwd);if(true){out.write("people({\"User_Age\":\"18\",\"User_Height\": 178,\"User_Weight\": 65});");}else{out.write("false");}}finally{out.close();}}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {// TODO Auto-generated method stubprocessRequest(req,resp);}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {// TODO Auto-generated method stubprocessRequest(req,resp);}}
客户端代码:10.11.18.188
// 用户登录 $("#submit").bind("click", function() { $.ajax({ type: "GET", async: false, url: "http://10.11.18.154/Yundongling/UserLogin", data: $("form#loginform").serialize(), dataType: 'jsonp', jsonp: 'callback', jsonpCallback:"people", success: function(json){ alert(json); alert(json.User_Age) if(json=="-"){ alert("用户名或密码错误!"); }else{ location.href="main.html"; } }, error:function(){ alert("出错"); }}); });
虽然是在局域网内测的,不过此段代码同样适用于跨域。
0 0
- jQuery Ajax jsonp 跨域
- jquery ajax跨域 jsonp
- jquery ajax跨域
- jquery ajax 跨域
- jquery ajax 跨域
- jquery跨域Ajax请求
- jquery ajax jsonp 跨域
- jquery + ajax 跨域parsererror
- JQuery跨域Ajax
- jquery ajax jsonp 跨域
- jquery ajax 跨域
- jquery ajax跨域 jsonp
- Jquery ajax 跨域
- jquery ajax 跨域
- jquery 跨域ajax jsonp使用方法
- AJAX跨域 jQuery JSONP 实践
- 用 jQuery 实现 Ajax 跨域
- jquery跨域ajax访问方法
- 前端技术博客学习
- phonegap初始页配置
- iOS 完全复制UIView
- 【手把手教你全文检索】Apache Lucene初探
- 微交易,时下最为红火
- Jquery ajax 跨域
- 5.一个三维数组,如何根据最后一维的数字大小正序排列,当然同时要保证索引的关联
- Window下Python环境变量配置
- 最优性条件
- Java中枚举的梗
- PhoneGap中HTTP链接自动调用本地浏览器解决办法
- 笔试题-编程
- svn: applying log message to xxxx Could not execute PROPPATCH错误
- C++中的static关键字