链接从 php 重定向
亲爱的,
我有网站链接的数据库,它在主文件中列出,当我尝试单击该链接时,它会重定向到该数据库链接。 我的代码是:
file: test.php
<?php
// getting from database
echo '<li onclick=\"window.location='.$result->website.'\">
<a href="#">'.$result->option.'</a></li>';
?>
The Main.html calls that test.php
while ajax
$.post("test.php", {queryString: ""+inputString+""}, function(data){
});
怎么做? 任何想法是否可以使用服务器端脚本?我的 php 代码有什么问题吗?
Dear all
I have database of website link, it list out in main file ,when i try to click that link it get to redirect on that database link.
my code is:
file: test.php
<?php
// getting from database
echo '<li onclick=\"window.location='.$result->website.'\">
<a href="#">'.$result->option.'</a></li>';
?>
The Main.html calls that test.php
while ajax
$.post("test.php", {queryString: ""+inputString+""}, function(data){
});
how to do it?
any idea Is it possible with serverside script? whats wrong with my php code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码不适用于无效 URL。 www.google.com 不是一个 URL,只是一个域名。因此,请跳过愚蠢的 Javascript 链接,而是使用:
并且您的 Javascript 成功函数似乎有些空,因此请使用 .load() ,例如:
Your code does not work for invalid URLs. www.google.com is not an URL, just a domain name. So skip the silly Javascript links, instead use:
And your Javascript success function seems somewhat empty, so instead use .load() like:
在venkat的评论后编辑:-
根据您的上一条评论,您遇到问题的代码如下:-
上面的代码实际上应该如下:-
添加“http:// ”字符串是变量“$link”将被用作HTTP URL,这需要提到这个“http://”字符串,主要是因为浏览器要使用的协议。在本例中,协议是 HTTP。
请始终记住,对于任何 URL,当存储在数据库/变量中时,URL 字符串的开头必须有一个字符串“http://”。
回到你问题中的代码,它是:-
现在“
window.location
”的位置并不完全正确。它应该放在“a”元素的“href”属性中,而不是放在“li”元素的“onclick”属性中。所以代码实际上应该是:-
希望有帮助。
Edited after venkat's comment:-
According to your last comment, the code you have problems with is the following:-
This above code should actually be the following:-
The reason for adding the "http://" string is that the variable "$link" is going to be used as an HTTP URL, which requires mentioning of this "http://" string, mainly because of the protocol to be used by the browser. In this case, the protocol is HTTP.
Always remember that for any URL, there must be a string "http://" at the beginning of the URL string, when stored in either a database / variable.
Coming back to the code in your question, which was:-
Now here the position of "
window.location
" is not totally correct. It should have been in "href" attribute of "a" element, instead of putting it in "onclick" attribute of "li" element.So the code should actually be:-
Hope it helps.