欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Ajax的jsonp方式跨域獲取數(shù)據(jù)的簡單實例

 更新時間:2016年05月28日 16:51:42   投稿:jingxian  
下面小編就為大家?guī)硪黄狝jax的jsonp方式跨域獲取數(shù)據(jù)的簡單實例。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

jsonp的調(diào)用,今天碰到了,正好整理了一下。

<!DOCTYPE html>
<html>
<head>
	<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
 <script type="text/javascript">
	$(document).ready(function(){
	 $("#b01").click(function(){
	 	$.ajax({//danielinbiti.txt文件內(nèi)容:getAInfo(["<input type='text' value='1222'/>"])
    url: 'http://192.168.12.21:8080/systemr/danielinbiti.txt',
    dataType: 'jsonp',//跨域設(shè)置jsonp
    processData: false,
    jsonpCallback:'getAInfo',//與文件中的getAInfo對應
    type: 'get',
    success: function(data) {
      $("#myDiv").html(data);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      alert('error');
      alert(XMLHttpRequest.status);
      alert(XMLHttpRequest.readyState);
      alert(textStatus);
    }
   });
	 });
	 $("#b02").click(function(){// 需要在后臺根據(jù)request獲取callback,然后才callback(需要返回的json內(nèi)容)的方式返回,getJSON是ajax的簡化,只支持json格式
	 	 $.getJSON("http://192.168.12.21:8080/systemr/b.do?jsoncallback=?",function(result){
		   $("#myDiv").html(result);
		  });
	 });
	});
</script>
</head>
<body>

<div id="myDiv"><h2>通過 AJAX 改變文本</h2></div>
<button id="b01" type="button">改變內(nèi)容01</button>
<button id="b02" type="button">改變內(nèi)容02getJSON</button>

</body>
</html>

以上這篇Ajax的jsonp方式跨域獲取數(shù)據(jù)的簡單實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論