我正在通過Jquery/Ajax
呼叫驗證我的html表單。這是由Php處理。在PHP頁面中處理後返回所有成功結果或錯誤結果到Jquery Success方法。如何接收jQuery成功方法()中的其他參數?
所以我想在jquery成功方法()中接收另一個參數。有什麼方法可以收到嗎?
例如:在此以下行代碼如果$numSearch
是== 0
elseif($numSearch === 0){
echo "<font color='red'>No Matches.</font>";
}
然後我想接收在jquery的成功方法的另一參數,以便可以裝入getDetails2(SearchValue);
功能。現在它的值是integer
。但它應該檢查值是否是整數,結果是否顯示。
PHP代碼:
require_once("corefile.php");
$search = (int) $_POST['data'];
$cdid = inputvalid($_POST['cdid']);
if($cdid == "ID"){
// if serach value is empty
if(empty($search)){
echo "<font color='red'>Search keyword required.</font>";
}
// if serach value is not empty
elseif(!empty($search)){
// start myqli_query to search
//$numserach
}
elseif($numSearch === 0){
echo "<font color='red'>No Matches.</font>";
}
}
jQuery代碼:
$(document).ready(function() {
$("#cdid").click(function() {
var SearchValue = $('#txt_name').val();
var cdid = $('#cdid').val();
$("#loading-image").show();
$.ajax({ //create an ajax request to load_page.php
type: "POST",
url: "doSearch.php",
data : {
'data' : SearchValue,
'cdid' : cdid
},
dataType: "html", //expect html to be returned
success: function(response){
if(Math.floor(SearchValue) == SearchValue && $.isNumeric(SearchValue)){
getDetails2(SearchValue);
}
$("#showSearchResult").html(response);
$('#visiableaftersearch').hide();
document.getElementById('txt_name').value='';
document.getElementById('txt_given_name').value='';
$("#loading-image").hide();
}
});
});
});
是的,我知道這是可以做到的使用'數據類型: 「jsone」'。但是不能使用'dataType:「html」'完成? – Babu 2014-11-25 06:30:22
在json中解析和發送AJAX數據非常乾淨 – 2014-11-25 06:31:49
是的,你說得對。 – Babu 2014-11-25 06:33:29