Jump to content

Processing js string via php function


PNXRMX

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.