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)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- jQuery使用JSONP實現(xiàn)跨域獲取數(shù)據(jù)的三種方法詳解
- 通過jsonp獲取json數(shù)據(jù)實現(xiàn)AJAX跨域請求
- JavaScript用JSONP跨域請求數(shù)據(jù)實例詳解
- 基于Jquery的跨域傳輸數(shù)據(jù)(JSONP)
- AJAX跨域請求之JSONP獲取JSON數(shù)據(jù)
- 使用jsonp實現(xiàn)跨域獲取數(shù)據(jù)實例講解
- AngularJS實現(xiàn)的JSONP跨域訪問數(shù)據(jù)傳輸功能詳解
- jsonp跨域請求數(shù)據(jù)實現(xiàn)手機號碼查詢實例分析
- AJAX跨域請求JSONP獲取JSON數(shù)據(jù)的實例代碼
- jsonp跨域獲取數(shù)據(jù)的基礎(chǔ)教程
相關(guān)文章
AJAX跨域請求數(shù)據(jù)的四種方法(實例講解)
下面小編就為大家?guī)硪黄狝JAX跨域請求數(shù)據(jù)的四種方法(實例講解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07Ajax 配合node js multer 實現(xiàn)文件上傳功能
這篇文章主要介紹了Ajax 配合node js multer 實現(xiàn)文件上傳功能,需要的朋友可以參考下2017-08-08