jquery ajax 跨域
来源:互联网 发布:苏州银行业数据统计 编辑:程序博客网 时间:2024/05/22 06:28
1、jsonp
html
<script type="text/javascript" src="http://www.youxiaju.com/js/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(function(){ $.ajax( { type:'get', url : 'http://www.youxiaju.com/validate.php?loginuser=lee&loginpass=123456', dataType : 'jsonp', jsonp:"jsoncallback", success : function(data) { alert("用户名:"+ data.user +" 密码:"+ data.pass); }, error : function() { alert('fail'); } } ); }) </script>
php
<?php header('Content-Type:text/html;Charset=utf-8'); $arr = array( "user" => $_GET['loginuser'], "pass" => $_GET['loginpass'], "name" => 'response' ); echo $_GET['jsoncallback'] . "(".json_encode($arr).")";
**
2、getJosn
**
$.getJSON("http://127.0.0.1/server/index.php/jsonp/getJson?callback=?", { id: "123456", site: "01" }, function(data) { console.log(data) alert(data.id + ',' + data.site + ',' + data.name); });
php
$get = $this->input->get(); $id = $get['id']; $site = $get['site']; $arr = array( "id" =>$id, "site" => $site, "name" => 'response' ); echo $_GET['callback'] . "(".json_encode($arr).")";
参考:
参考文章
jsonp原理
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访问方法
- Android stadio litepal
- Linux目录结构和常用命令
- Swift中自定义Log
- PDF格式文档怎样编辑页面内容
- git/repo rebase 用途
- jquery ajax 跨域
- 欢迎使用CSDN-markdown编辑器
- busybox 启动applet分析
- TIJ 复习笔记3
- Spring3 整合Hibernate3.5 动态切换SessionFactory (切换数据库方言)
- Aspose.cell
- android:inputType常用取值
- 171 git subtree 管理子项目
- socket(http或者其他网络请求)在主线程中使用会报错:NetworkOnMainThreadException