我试图在ajax响应(wall_list.php)中调用date_cal()
javascript函数。每件事都很好,我得到了正确的响应。但它没有调用date_cal()函数。
主文件:
$。AJAX({
url: 'wall_list.php',
data:"dt_from="+dt_from+"&dt_to="+dt_to+"&week="+week+"&month="+month+"&dt_filter="+dt_filter+"&fan="+fan+"&gender="+gender+"&pageNumber="+pagenumber,
type: 'POST',
success: function (resp) {
if(resp)
{
//alert(resp);
document.getElementById('wall_listdiv').innerHTML=resp;
}
Wall_list.php
一些代码...................
> <td id="<?php print $key; ?>" class="tm_td" valign="top" colspan=2>
>
<script language="JavaScript">
date_cal('<?php print $commentcreatetimearr[$key]; ?>','<?php print $key; ?>');
</script>
> </td>
一些代码......................
它没有在那里调用javascript。
任何人都可以解释如何回应所有这些功能。
答案 0 :(得分:2)
你去吧
$.ajax({
url: 'wall_list.php',
data: "dt_from="+dt_from+"&dt_to="+dt_to+"&week="+week+"&month="+month+"&dt_filter="+dt_filter+"&fan="+fan+"&gender="+gender+"&pageNumber="+pagenumber,
type: 'POST',
success: function (resp){
if(resp){
$("#wall_listdiv").html(resp);
}
},
dataType: 'html'
});
您要做的是,将返回dataType
指定为html
。
来自jQuery API
If html is specified, any embedded JavaScript inside the retrieved data is executed before the HTML is returned as a string. Similarly, script will execute the JavaScript that is pulled back from the server, then return the script itself as textual data.
此处提供更多信息:jQuery.ajax() - jQuery API
答案 1 :(得分:0)
PHP:
<?php echo $commentcreatetimearr[$key]; ?>
JS:
$.ajax({
url: 'wall_list.php',
data:"dt_from="+dt_from+"&dt_to="+dt_to+"&week="+week+"&month="+month+"&dt_filter="+dt_filter+"&fan="+fan+"&gender="+gender+"&pageNumber="+pagenumber,
type: 'POST',
success: function (resp) {
if(resp){
$('#wall_listdiv').html(date_cal(resp));
}