tags:

views:

39

answers:

2

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);
   }
}

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 ?>);
   }
}  

Is this possible? Can anybody out there please help me. I can't seem to get around this.
Many thanks in advance.

A: 

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.

Jonathan Sampson
Formatting the getinfo.php worked. Thanks for your help.
DGT
A: 

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?

Abs
Thank you, Abs. I'll try out your first suggestion and format it within the getinfo.php. What the php function basically does is, searches the data.desc for something like the following <span> tags:<span id="name.123" class="cite">some note</span> and then converts them into: <a class="link" href="http://www.mypage.com/page.php?ln=xxx#name">some note</a>, basically removing the 'name' in the <span id="name.123"...> and appending it to URL and then substituting the latter for the entire <span> tag. So, when the html(data.desc) is loaded, all the <span>...</span> shows up as a hyperlinks.
DGT