PNXRMX Posted October 21, 2008 Share Posted October 21, 2008 Hi, I want to create a live preview showing the results of changes in various textboxes. This is working fine using: onChange='changeContent(\"ttitle$t\",this.value);' The problem is that 'this.value' also often contains BBCode or variables that I want to process. I would normally do this using my php function brand(), which works fine in normal circumstances. I want to process this.value using the php function brand(). I've come up with the following: Code on page: onChange='changeContent(\"ttitle$t\",jsBrand(this.value));' jsBrand function: function jsBrand(string) { var req = Inint_AJAX(); //This function does definitely work req.open("POST", "items/jsbrand.php",false); req.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); var encoded = ""; encoded = "string=" + escape(string); req.send(encoded); if (req.status != 200) { alert("There was a communications error: " + req.responseText); return; } else { return string; } } jsbrand.php: <? //set IE read from page only not read from cache header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header ("Cache-Control: no-cache, must-revalidate"); header ("Pragma: no-cache"); header("content-type: application/x-javascript"); $string=$_POST['string']; $brandedstring=brand($string); echo "string = '$brandedstring';"; ?> No matter what I put in the PHP page, the function always returns the original string (this.value) rather than the processed string. I have tried using GET, tried different headers, tried echo "string = 'test';"; but it still returned this.value, tried removing the ; within the echo, tried accessing the php file using different paths... pretty much everything I can think of as a javascript noob Does anyone know how to fix this? Thanks a lot... Link to comment https://forums.phpfreaks.com/topic/129427-processing-js-string-via-php-function/ Share on other sites More sharing options...
PNXRMX Posted October 21, 2008 Author Share Posted October 21, 2008 After some searching I decided to include req.responseText in the alert. It outputs a fatal error, because of undefined function 'brand'. This function is definitely defined in the file as a PHP function... I'm kinda stuck here ??? Link to comment https://forums.phpfreaks.com/topic/129427-processing-js-string-via-php-function/#findComment-671090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.