利用jquery php来实现js的跨域请求
html代码:
- <html>
- <script src="jquery.min.js" type="text/javascript" ></script>
- <script>
- function pushstar(){
- var reval= '';
- var host = 'www.xxx.com';
- //editor.sync();
- var star= document.getElementById('content');
- value ='这里设置内容';
- $.ajax({
- async:false,
- type: 'GET',
- url: "http://" + host +"/index.php" ,
- data:{param:value} ,
- jsonpCallback:"callbak",
- dataType:'jsonp',
- jsonp: 'callbak',
- error:function(request){
- //var jsona = $.parseJSON(msg);
- alert('fail');
- },
- success:function(msg){
- if(msg[0] == 1){
- alert(msg[1]);
- }else{
- alert('fail');
- }
- },
- });
- }
- </script>
- 点击<input type="button" onclick="pushstar()">
- </html>
<html>
<script src="jquery.min.js" type="text/javascript" ></script>
<script>
function pushstar(){
var reval= '';
var host = 'www.xxx.com';
//editor.sync();
var star= document.getElementById('content');
value ='这里设置内容';
$.ajax({
async:false,
type: 'GET',
url: "http://" + host +"/index.php" ,
data:{param:value} ,
jsonpCallback:"callbak",
dataType:'jsonp',
jsonp: 'callbak',
error:function(request){
//var jsona = $.parseJSON(msg);
alert('fail');
},
success:function(msg){
if(msg[0] == 1){
alert(msg[1]);
}else{
alert('fail');
}
},
});
}
</script>
点击<input type="button" οnclick="pushstar()">
</html>
index.php代码:
- <?php
- /*
- *回调文件
- */
- $arr[] =1;
- $arr[] ='cuccess';
- echo 'callbak('.json_encode($arr).')';exit;
- ?>