[英]Jquery ajax get request
我是 jquery 和 php 的新手,我有兩個輸入字段,zip 和城市,城市應 output 基於用戶輸入的 zip 的值。 jquery 腳本應調用 URL: http://domain.com/city?zip.php= "zip; 這樣 zip.php 將返回一個 echo 值,將 883434378106 的城市字段輸入
我嘗試使用 ajax getXMLHTTP。 有時有效但有時無效
請參考下面的代碼片段:
<input type="text" id="zip_code" name="zip_code" />
<input type="text" id="city" name="city" />
<script type="text/javascript">
// Some Jquery code here for ajax get request to http://domain.com/city?zip.php
</script>
如果您使用的是jquery,請使用$ .ajax選項代替getXMLHTTP
function passzipvalue(zip)
$.ajax({
type: "GET",
url : 'http://domain.com/city.php='
data:"zip="+zip,
success: function(msg){
$("#formsData").html(msg);
}
});
}
像這樣或
$.get('http://domain.com/city.php?zip='+zip,function (msg){
$('#formsData').html(msg);
});
如果要在某些輸入字段中填充它,請使用.val
而不是.html
$.ajax({
url: 'url',
beforeSend: function (xhr) {
//show loading
}
}).done(function (data, xhr) {
//hide loading
//success
}).fail(function (xhr) {
//hide loading
//error
});
使用jQuery AJAX 。 例如:
var zip = $('#zip').val();
$.get('http://domain.com/city.php?zip='+zip,function (data){
$('#city').val(data);
});
使用jQuery.get
,記錄在這里 。 在成功處理程序中,使用data參數填充城市輸入。
樣品:
$.get('http://domain.com/city.php?zip='+$('#IdOfZipInput').val(), function (data){
$('#IdOfCityInput').val(data);
});
嘗試使用jQuery Ajax
$.ajax({
type: "POST",
url: 'sample/test.php',//your url
data: data,//data to be post
cache: false,
success: function(html) {
alert(html);//response from the server
}
});
$.ajax({
url: 'http://domain.com/city.php?zip='+zip,
type: get,
success: function(data){
$("div").html(data);
}
});
use this data will be displayed
如果它是一個不斷更新的元素,則使用jquery.post作為ie,即緩存“獲取”結果。
jQuery.post('call.php',{action:“ get”},function(data){
jQuery('#content').append(data);
});
在此處找到本教程http://vavumi.com/?p=257
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.