PHP新手求助:点击按钮跳转至线上站点而非localhost问题
Hey there! I see you're a PHP newbie working with XAMPP, and even after fixing the global localhost-to-live-site redirect issue, your quote button is still misbehaving. Let's walk through some common fixes for this specific problem:
1. 强制清除浏览器缓存
Browsers love to cache old JavaScript files, which might mean your updated click event code isn't even being loaded. Try these steps:
- Press
Ctrl + Shift + R(Windows/Linux) orCmd + Shift + R(Mac) to do a hard refresh of your local page. - If that doesn't work, go into your browser's settings and clear the cache for your localhost domain specifically.
2. 检查HTML中的<base>标签
A common culprit here is a forgotten <base> tag in your HTML <head> section. If this tag is set to your live site URL (https://www.website.com), all relative links (like quote-page.php) will resolve to the live site instead of localhost.
Check your HTML for something like this:
<base href="https://www.website.com/">
If you find it, either remove it entirely or update it to your local URL:
<base href="http://localhost/">
3. 确认没有其他JS代码覆盖你的点击事件
It's possible another script on your page is overriding the click event for #quote-button. To test this, try temporarily removing other JavaScript files from your page and see if the button works as expected.
You can also add a console log to your event to confirm it's firing:
$('#quote-button').click(function(){ console.log("Local click event triggered!"); location.href="quote-page.php"; return false; });
Open your browser's dev tools (F12) and check the Console tab when you click the button. If you don't see the log message, your event isn't being executed at all.
4. 改用绝对本地路径测试
To rule out any relative path resolution issues, try using the full localhost URL in your click event:
$('#quote-button').click(function(){ location.href="http://localhost/quote-page.php"; return false; });
If this works, it means your relative path is being resolved incorrectly (likely due to the base tag or server configuration).
5. 检查XAMPP虚拟主机配置(如果使用)
If you've set up virtual hosts in XAMPP, double-check that your local site's configuration isn't accidentally pointing to the live server. Open your httpd-vhosts.conf file (usually in XAMPP/apache/conf/extra/) and verify that your local domain points to your project folder on your computer.
内容的提问来源于stack exchange,提问作者Reema

