开发者

format JSON value with a php function and print result inside a div#id

开发者 https://www.devze.com 2022-12-20 17:13 出处:网络
So far, I have got the fo开发者_Python百科llowing: $.getJSON(\'getinfo.php\', { id:id }, parseInfo);

So far, I have got the fo开发者_Python百科llowing:

$.getJSON('getinfo.php', { id:id }, parseInfo);

function parseInfo(data) {
   $('div#info').fadeOut("fast", function() {
      $('div#info').html(data.desc);
   }
}

I am able to print the results (data.desc) inside the div#info html tag, but before I do so, I want to format data.desc with my php function. So, basically I want to do something like this,

function parseInfo(data) {
   $('div#info').fadeOut("fast", function() {
      <?php 
         $formated = some_php_function(data.desc);
      ?>  
      $('div#info').html(<?php echo $formated ?>);
   }
}  


You won't be able to call a PHP function in the middle of a Javascript function. You'll have to format this value before you send it through as a JSON value, or you'll have to duplicate your PHP function in Javascript and use it client-side.


Like I say, why not do that formatting function within getinfo.php?

Another option would be to write a JavaScript function instead of a PHP one to format your variable. What sort of formatting do you need to do on it?

0

精彩评论

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

关注公众号