我正在通过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