2013-02-16 104 views
0

我正在处理1个JavaScript文件和1个php文件的简单项目。我正在尝试使用ajax来调用一些php代码,然后这些代码将文本显示在Lightbox上。我的问题是,我收到以下错误:PHP网络错误

此错误指向我的PHP文件。

"NetworkError: 404 Not Found - http://localhost/folder/folder/dictionary.php" 

我已经检查(和双重检查)我所有的代码,但我不知道如何解决这个错误。有人可以帮我吗?我将在下面提供我的JavaScript和PHP代码:

的JavaScript:

$(document).ready(function() { 
    $("#SearchField").submit(function(e) { 
     e.preventDefault(); 

     // grabs all post variables in the form 
     var info = $(this).serialize(); 

     $.post('dictionary.php', info, function(data) { 
      $('.DictionaryContentWrapper').append(data); 
     }); 

     // prevent server from refreshing page 
     return false; 
    }); 
}); 

PHP:

$input = $_POST['input']; 
echo $input; 

目录结构:

index.php 
Widget 
    - **input.js** 
    - getURL.php 
    - **dictionary.php** 
lightbox 
    - lightbox.css 
    - lightbox.js 
+0

什么是你的文件叫什么名字?什么是目录结构? – 2013-02-16 01:43:16

+0

你是否在桌面上本地运行此程序,或者您是否有某个Web服务器? – j08691 2013-02-16 01:45:36

+0

我已经提供了上面的目录结构,我还突出了我提供代码的文件。 – JaPerk14 2013-02-16 01:46:27

回答

0

一个简单的解决办法是使用相对于Web服务器根目录的绝对路径。

喜欢的东西:

$.post('/Widget/dictionary.php', info, function(data) { 

但是,假设你的index.php驻留在该网站的根目录 - http://localhost/index.php - 但不是从您发布的信息很明确:该错误消息不似乎适合目录结构。

编辑:如果要调用脚本从index.php,你也可以使用:

$.post('Widget/dictionary.php', info, function(data) { // path relative to index.php 
+0

“index.php”文件位于文件夹“最终字典小工具”,它位于本地主机 – JaPerk14 2013-02-16 01:53:16

+0

@ JaPerk14你应该发布一个更清晰的目录结构在你的问题,但在这种情况下,绝对路径将是'/ Final Dictionary Widget/Widget/dictionary.php'。然而,我会摆脱路径中的空间。 – jeroen 2013-02-16 01:55:08

+1

Ty,这为我工作 – JaPerk14 2013-02-16 02:01:54