开发者

Calling javascript function inside jquery ajax response file code

开发者 https://www.devze.com 2023-02-06 00:24 出处:网络
I am trying to call date_cal() javascript function inside ajax response (wall_list.php).Every thing is fine am getting correct response. But its not calling date_cal() function.

I am trying to call date_cal() javascript function inside ajax response (wall_list.php).Every thing is fine am getting correct response. But its not calling date_cal() function.

main file:

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

it's not calling javascript there.

Can anyone explain how to all this function in response.


here you go

$.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'
});

What you want to do is, specify the return dataType as html. From 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.

More information here: jQuery.ajax() - jQuery API


for example
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));
  }  
0

精彩评论

暂无评论...
验证码 换一张
取 消