Im使用jquery.load函数查询将输出一些数据的php文件。现在,有时脚本将不返回任何内容。在这种情况下,我可以让load函数不将任何数据放入我指定的div中吗?(现在它清除了div,只放了一个空白的白色区域。
谢谢!
尝试使用$.get;
$.get('<url>',{param1:true},function(result){
if(result) {
$('selector').html(result);
}
else {
//code to handle if no results
}
});
使用$.get
http://api.jquery.com/jQuery.get/
除了@jerjer的帖子,你还可以使用这个:
var paramData= 'param=' + param1 + '&user=<?echo $user;?>';
$.ajax({
type: "GET",
data:paramData,
url: "myUrl.php",
dataType: "json", // this line is optional
success: function(result) {
// do you code here
alert(result); // this can be an any value returned from myUrl.php
},
statusCode: {
404: function() {
alert('page not found');
}
}
});