開發中遇到一個國外的接口,需要先調用php頁面,當php頁面調用成功後,才能調用第二個接口完成數據的查詢。
直接上代碼:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(function(){
//按鈕單擊時執行
$("#testAjax").click(function(){
//Ajax調用處理
var html = $.ajax({
type: "GET",
url: "https://itra.run/checkRes.php",
data: "name=min&surname=liu&birthdate=1991-05-19&idca=58999",
async: false
}).status;
$("#myDiv").html('<h2>'+html+'</h2>');
});
});
</script>
</head>
<body>
<div id="myDiv"><h2>文本</h2></div>
<button id="testAjax" type="button">獲取PHP的http狀態</button>
</body>
</html>
舉一反三,獲取PHP頁面的返回的數據
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(function(){
//按鈕單擊時執行
$("#testAjax").click(function(){
//Ajax調用處理
var html = $.ajax({
type: "GET",
url: "https://itra.run/checkRes.php",
data: "name=min&surname=liu&birthdate=1991-05-19&idca=58999",
async: false
}).responseText;
$("#myDiv").html('<h2>'+html+'</h2>');
});
});
</script>
</head>
<body>
<div id="myDiv"><h2>通過 AJAX 改變文本</h2></div>
<button id="testAjax" type="button">Ajax改變內容</button>
</body>
</html>