使用php函数格式化JSON值并在div#id内打印结果 [英] format JSON value with a php function and print result inside a div#id

查看:90
本文介绍了使用php函数格式化JSON值并在div#id内打印结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我有以下内容:

So far, I have got the following:

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

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

我能够在div #info html标签内打印结果(data.desc),但在我这样做之前,我想用我的php函数格式化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 ?>);
   }
}  


推荐答案

您将无法在Javascript函数中调用PHP函数。您必须在将此值作为JSON值发送之前格式化此值,否则您将不得不复制PHP函数在Javascript中并使用它在客户端。

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.

这篇关于使用php函数格式化JSON值并在div#id内打印结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆