简体   繁体   English

(jQuery)尝试使用Ajax查找php文件时出现404错误

[英](Jquery) 404 error when trying to find php file with ajax

I've been trying to fix this for the past 2 hours, but I haven't been able to fix it. 在过去的2个小时中,我一直在尝试解决此问题,但我一直无法解决。 So I have the current filesetup: 所以我有当前的文件设置:

classes
-html
--index.html
--front_gallery.php
-javascript
--gallary.js

And I've been following the tutorial here: http://webdevelopingcat.com/jquery-php-beginner-tutorial-ajax/ , and I've followed it almost exactly. 我一直在这里关注该教程: http : //webdevelopingcat.com/jquery-php-beginner-tutorial-ajax/ ,并且我几乎完全遵循了该教程。 I'm currently just running the site off the computer. 我目前仅在计算机上运行该网站。

So, if I run it off the Adobe Brackets live preview, I get the 404 error, saying that the file is not found. 因此,如果我在Adobe Brackets实时预览中运行它,则会收到404错误,表示找不到该文件。 However, if I run it directly, I get this error: 但是,如果直接运行它,则会出现此错误:

 XMLHttpRequest cannot load file:///C:/Users/myaka_000/Dropbox/Public/dylan_ferris_website/classes/html/front_gallery.php. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.

Here is the gallery.js code: 这是gallery.js代码:

$(document).ready(function() {

$(function() {
    $("#contact").submit(function(e) {
        e.preventDefault();

        var formData = $(this).serialize();
        window.console.log( formData )

        $.ajax({
            type: "POST",
            url: "front_gallery.php",
            data: formData,
            success: function(resp){
                window.console.log(resp);
            }
        });
    });
});


});

front_gallery.php: front_gallery.php:

<?
print_r( $_POST );

You are trying to POST this file, assuming they are in the same directory, but it's wrong. 您假设这些文件位于同一目录中,则尝试发布该文件,但这是错误的。

Try to replace 尝试更换

url: "front_gallery.php",

with

url: "../html/front_gallery.php",

You try replace: 您尝试替换:

url: 'front_gallery.php"

with

url: '/front_gallery.php"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM