I am looking to prevent the symbol "&" from being replaced by "&
" within my URL, specifically within JavaScript.
Just to expand on this requirement, I am getting my url from an oracle database table, which I then use within Oracle Application Express, to set the src attribute of an iframe to this url.
FYI, the url stored in the Oracle table is actually stored correctly, i.e.
http://example.com/xml/getInfo?s=pvalue1&f=mydir/Summary.xml
What appears in my use when trying to pass over into iframe src using JavaScript is:
http://example.com/xml/getInfo?s=pvalue1&f=mydir/Summary.xml
which basically returns a page cannot be found
I suspect you are doing something like this:
1) Selecting the URL text from the database into an Apex page item.
2) In Javascript, getting the URL text from the page item and using it to set the iframe source.
When you select the value in step 1, Apex will automatically replace the "&" by "&" so that the page HTML is valid - it will be something like:
<input type="hidden" id="P1_URL"
value="http://mydomain.com/xml/getInfo?s=pvalue1&f=mydir/Summary.xml" />
You will therefore have to reverse the transformation in your Javascript code - something like:
document.getElementById('myIframe').src = $v('P1_URL').replace('&','&');
I had the same problem and it caused me a lot of grief using PHP and JS.
This was how I solved the problem, using substring(0,1)
.
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:
phpfilename.php?date=2012-10-31&type=2
Yes, it's a long example, but I'm sure you can extract all the extra junk to be a minimalist example. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With