大网数据广告活动
网站运营与故障问答

Htaccess won't work with ajax/php

· 52CE 我爱测

Sending ajax request by jquery doesn't working with htaccess. Works without htaccess. product_configurator.php -> fetch_data_p.php $.ajax({ url:"fetch_data_p.php", method:"POST", htaccess RewriteRule ^(product_configurator)\.html…

问题原文

原帖链接 · Mantykora 7 · CC BY-SA 4.0

Sending ajax request by jquery doesn't working with htaccess. Works without htaccess.

product_configurator.php -> fetch_data_p.php

$.ajax({
            url:"fetch_data_p.php",
            method:"POST",

htaccess RewriteRule ^(product_configurator)\.html/(\d+)&(\d+)$ $1.php?prometheus_id=$2&id=$3 [L]

  1. it works http://mantykora.cleoni.com:8080/photo_gallery/public/product_configurator.html?prometheus_id=10082&id=30
  2. did not work http://mantykora.cleoni.com:8080/photo_gallery/public/product_configurator.html/10082&30

Why is this happening?

@MrWhite SOULUTION

$.ajax({
    url:"http://localhost/photo_gallery/public/fetch_data_p.php",
    method:"POST",

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

The problem would seem to be that you are using a relative client-side URL to make the AJAX request and since you are using a URL at a different path depth fetch_data_p.php is not found.

The AJAX request for fetch_data_p.php is relative to the visible URL in the browser. You need to make this URL root-relative (starting with a slash). eg. /photo_gallery/public/fetch_data_p.php.

Currently:

When at the URL /photo_gallery/public/product_configurator.html?prometheus_id=10082&id=30, your AJAX call to fetch_data_p.php resolves to /photo_gallery/public/fetch_data_p.php and it works.

However, when at the URL /photo_gallery/public/product_configurator.html/10082&30, your AJAX call to fetch_data_p.php resolves to /photo_gallery/public/product_configurator.html/fetch_data_p.php which naturally fails - 404 Not Found.

This doesn't really have anything to do with the URL rewrite itself in .htaccess, except for the fact the client-side URL is different and importantly, a different path depth. The AJAX call itself is not being rewritten.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2020-11-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。