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
Share on other sites

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