Ajax请求相关的放置在不同的文件夹不同的文件 [英] ajax request related to different files placed in different folders

查看:392
本文介绍了Ajax请求相关的放置在不同的文件夹不同的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹命名为 HTML

I have a folder named html

 html/index.php
 html/jquery/primary.js
 html/ajax/request.php

的index.php 文件是HTML文件夹和 primary.js 中的子文件夹 jQuery的现在我实现了由 primary.js 文件中像这样

Index.php file is in html folder and primary.js in the sub folder jquery Now I have made an ajax request from primary.js file like this

$.post('../ajax/request.php',{id:"//some id"},function(result){
     // some statments                      
}); 

但这里的Ajax请求是不完整的。它说未找到文件我在想primary.js在jQuery的文件夹,所以我用 ../ AJAX / 来回去一个目录并跳转到 AJAX ,但它似乎并没有工作令人惊讶,当我移动的文件,以 HTML / request.php 并提出Ajax请求只需 request.php 它的工作。当我用 ../ request.php (因为 primary.js 是在另一个目录 jQuery的我做了一个退一步,定向到文件,但它不能正常工作。

But here the ajax request is incomplete. It says file not found I was thinking primary.js is in jquery folder so i used ../ajax/ to go back one directory and jump to ajax but it does not seem to work surprisingly when I moved the file to html/request.php and made ajax request simply request.php it worked. and when I used ../request.php (since primary.js is in another directory jquery I made one step back and directed to file but it does not work.

我所理解的是无论你在哪里做的Ajax请求,Ajax请求的文件必须是目录中的index.php ,应在Ajax请求中使用像这样 request.php 无论身在何处 primary.js 文件

What I have understood is no matter where You do the ajax request, the ajax request file must be within the directory of index.php and should be used in ajax request like this request.php no matter where the primary.js file is

难道任何一个澄清的东西更清楚。任何帮助是极大的AP preciated。谢谢

Could any one clarify the things more clearly. any help is greatly appreciated. Thanks

推荐答案

你的 $。交的路径是相对URL,因为你的JavaScript文件被加载并从那里执行。

The path for your $.post is relative to the URL you are currently on because your javascript file is loaded and executed from there.

如果你在你的index.php是在 / HTML / 文件夹,这样的URL到您的Ajax请求应 AJAX / request.php 代替。

If you are in index.php you are in the /html/ folder so the url to your ajax request should be ajax/request.php instead.

这篇关于Ajax请求相关的放置在不同的文件夹不同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆