gpt4 book ai didi

php - 在 jquery ajax 响应文件代码中调用 javascript 函数

转载 作者:行者123 更新时间:2023-11-30 18:48:21 25 4
gpt4 key购买 nike

我正在尝试在 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

Some code...................

>   <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>

Some code......................

它不会在那里调用 javascript。

任何人都可以解释如何响应所有这些功能。

最佳答案

给你

$.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

关于php - 在 jquery ajax 响应文件代码中调用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4733086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com