Markus_Newhart Posted January 12, 2014 Share Posted January 12, 2014 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. Quote Link to comment Share on other sites More sharing options...
Skewled Posted January 12, 2014 Share Posted January 12, 2014 Provide some code otherwise this is too vague to even answer. Quote Link to comment Share on other sites More sharing options...
Markus_Newhart Posted January 12, 2014 Author Share Posted January 12, 2014 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); } Quote Link to comment Share on other sites More sharing options...
Markus_Newhart Posted January 16, 2014 Author Share Posted January 16, 2014 Bump. I still need help. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted January 16, 2014 Share Posted January 16, 2014 (edited) You cannot mix javascript and PHP code together. Is data the response from an ajax request? if it is, then call the showBBcodes PHP function when you receive the ajax request in PHP. Edited January 16, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 16, 2014 Share Posted January 16, 2014 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. Quote Link to comment Share on other sites More sharing options...
Markus_Newhart Posted January 16, 2014 Author Share Posted January 16, 2014 Alright, thanks. Guess ill just reload the page when ever the player posts stuff... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.