Stop & turning in to & – solution

Posted on

Recently I had to solve a painful problem using PHP and Javascript.

I discovered that trying to pass, or create a URL with &val=val was becoming &=val and couldn’t find a way to fix it.
As I was implementing the script in to a Joomla site, it was becoming automatic. Without the Joomla integration, it worked ok. It was very strange, but I have now found the solution.

This was how I solved the problem, using substring(0,1).
Here’s an example of how to maybe use this code.
function callAJAX()
    {      
        var var_Date = document.getElementById('DateAJAX').value;    
        var l2 = '&type=' + <?php echo $type; ?>; 
        var l2=l2.substring(0,1) + '<?php echo "type="  . $type; ?>';  // stupid js fix 
        jsfunction('ajaxdiv', 'phpfilename.php?date=' +var_Date + l2,'<? echo $num; ?>'); 
    }

The URL will result in something like this:

phpfilename.php?date=2012-10-31&type=2

 

I hope this helps all the other geeky boffins out there .

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s