2014-11-22 60 views
0

我一直在嘗試修復過去2小時內的這個問題,但是我一直無法修復它。所以,我有當前filesetup:(jquery)嘗試使用ajax查找php文件時出現404錯誤

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

我的心一直在這裏以下教程:http://webdevelopingcat.com/jquery-php-beginner-tutorial-ajax/,我也跟着它幾乎一模一樣。我目前只是從電腦上運行網站。

所以,如果我從Adobe Brackets實時預覽中運行它,我會得到404錯誤,說沒有找到該文件。但是,如果我直接運行它,我得到這個錯誤:

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. 

這裏是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:

<? 
print_r($_POST); 
+0

的http:// STAC koverflow.com/questions/20041656/xmlhttprequest-cannot-load-file-cross-origin-requests-are-only-supported-for-ht – MH2K9 2014-11-22 04:31:30

回答

0

您正在嘗試POST這個文件,假設它們在同一個目錄中,但它是錯誤的。

嘗試

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

更換

url: "front_gallery.php", 

您嘗試替換:

url: 'front_gallery.php" 

url: '/front_gallery.php" 
相關問題