dongsiju1941 2014-11-22 04:26
浏览 63

(Jquery)404尝试使用ajax查找php文件时出错

I've been trying to fix this for the past 2 hours, but I haven't been able to fix it. 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. 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. 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:

$(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:

<?
print_r( $_POST );
  • 写回答

2条回答 默认 最新

  • dongnao3990 2014-11-22 04:32
    关注

    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",
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)