利用jquery PHP来实现js的跨域请求
<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>
<?PHP /* *回调文件 */ $arr[] =1; $arr[] ='cuccess'; echo 'callbak('.json_encode($arr).')';exit; ?>