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?
精彩评论