Jump to content

Recommended Posts

I need some help. Im trying to call a php function in ajax. The data variable needs to be inside the called function.

Like: 

_("statusarea").innerHTML = '<div><?php showBBcodes('+data+'); ?></div>';
				

But no matter what i do it wont call it and if it does call it it wont show the data.

Link to comment
https://forums.phpfreaks.com/topic/285310-phpajax-help/
Share on other sites


function showBBcodes($text) {

// BBcode array
$find = array(
'~\[b\](.*?)\[/b\]~s',
'~\[i\](.*?)\[/i\]~s',
'~\[u\](.*?)\[/u\]~s',
'~\[quote\](.*?)\[/quote\]~s',
'~\[size=(.*?)\](.*?)\[/size\]~s',
'~\[color=(.*?)\](.*?)\[/color\]~s',
'~\[url\]((?:ftp|https?)://.*?)\[/url\]~s',
'~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s'
);

// HTML tags to replace BBcode
$replace = array(
'<b>$1</b>',
'<i>$1</i>',
'<span style="text-decoration:underline;">$1</span>',
'<pre>$1</'.'pre>',
'<span style="font-size:$1px;">$2</span>',
'<span style="color:$1;">$2</span>',
'<a href="$1">$1</a>',
'<img src="$1" alt="" />'
);

// Replacing the BBcodes with corresponding HTML tags
return preg_replace($find,$replace,$text);
}

Link to comment
https://forums.phpfreaks.com/topic/285310-phpajax-help/#findComment-1464985
Share on other sites

code in a browser cannot CALL a function on a server. the only thing that a browser can do is make a http request to the server, where the server-side code takes the submitted data (post, get, files, or cookie) and uses those values to perform some action.

 

i recommend you read up on what ajax stands for and read some ajax/php examples.

Link to comment
https://forums.phpfreaks.com/topic/285310-phpajax-help/#findComment-1465408
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.