如何防止符号“&”的出现不再被“&”取代

发布于 2024-09-05 03:39:24 字数 489 浏览 6 评论 0原文

我正在寻找防止符号“&”在我的 URL 中(特别是在 JavaScript 中)被替换为“&”。

为了扩展此要求,我从 Oracle 数据库表中获取 url,然后在 Oracle Application Express 中使用该表,将 iframe 的 src 属性设置为此 url。

仅供参考,存储在 Oracle 表中的 url 实际上存储正确,即

http://example.com/xml/getInfo?s=pvalue1&f=mydir/Summary.xml

当尝试使用 JavaScript 传递到 iframe src 时,在我的使用中出现的内容是:

http://example.com/xml/getInfo?s=pvalue1&f=mydir/Summary.xml

基本上返回一个无法找到的页面

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山色无中 2024-09-12 03:39:24

我怀疑您正在做这样的事情:

1)从数据库中选择 URL 文本到 Apex 页面项中。

2) 在 Javascript 中,从页面项获取 URL 文本并使用它来设置 iframe 源。

当您在步骤 1 中选择值时,Apex 将自动替换“&”通过“&”这样页面 HTML 是有效的 - 它将类似于:

<input type="hidden" id="P1_URL" 
 value="http://mydomain.com/xml/getInfo?s=pvalue1&f=mydir/Summary.xml" />

因此,您必须在 Javascript 代码中反转转换 - 类似于:

document.getElementById('myIframe').src = $v('P1_URL').replace('&','&');

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('&','&');
余厌 2024-09-12 03:39:24

我也遇到了同样的问题,这让我在使用 PHP 和 JS 时感到非常痛苦。

这就是我使用 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; ?>'); 
    }

URL 将导致类似以下内容:

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

是的,这是一个很长的示例,但我确信您可以提取所有额外的垃圾作为一个极简示例。 :)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文