[英]Unable to display facebox with custom content
在我的html文件中,我有一個javascript函數,
$("#contactopts").change(function() {
var response = simplefunc();
$('#sampID').html(response);
$.facebox($('#sampID'));
}
函數simplefunc
是一個jquery函數,它從后端返回一個html文件作為響應。
我期望一個帶有從后端發送的html文件的內容的facebox。 但是相反,我得到了一個空的facebox。 我嘗試了console.log(response
說響應是undefined
..
有人可以告訴我我在做什么錯嗎? 我可以看到我缺少一些基本知識。
try like this,
$("#contactopts").change(function() {
var response = simplefunc();
//$('#sampID').html(response);
//$.facebox($('#sampID'));
}
function simplefunc()
{
$.ajax({
type : "POST",
url : "sample_ajax_page.php",
data : {xxx:xxx,yyy:yyy},
success : function(html){
$('#sampID').html(html);
$.facebox($('#sampID'));
}
}
J-Query或javascript不會等待ajax返回,這就是您將其空白的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.