我需要在哪里存储AJAX的文本文件才能检索它?

时间:2013-08-30 18:04:21

标签: php jquery ajax

这个问题可能需要更多阅读而不是真正的价值,但我正在使用教科书来学习AJAX,而对AJAX的介绍性练习是在下面运行此代码。在第16行,有一个GET请求来检索.txt文件,但程序没有这样做。我需要将文本文件放在XAMPP目录中,还是放在XAMPP中的目录中,以获得所需的结果?任何帮助都非常感谢。

-- badHero - bad examples...

DROP TABLE IF EXISTS badHero;

CREATE TABLE badHero (
  name varchar(50),
  powers varchar(250),
  villain varchar(50),
  plot varchar(50),
  mission varchar(50),
  age int
);

INSERT INTO badHero VALUES(
  'The Plumber',
  'Sewer snake of doom, unclogging, ability to withstand smells',
  'Septic Slime Master',
  'Overcome Chicago with slime',
  'Stop the Septic Slime',
  37
  );

INSERT INTO badHero VALUES (
  'Binary Boy',
  'Hexidecimation beam, obfuscation',
  'Octal',
  'Eliminate the numerals 8 and 9',
  'Make the world safe for binary representation',
  19
);

INSERT INTO badHero VALUES (
  'The Janitor',
  'Mighty Mop',
  'Septic Slim Master',
  'Overcome New York with slime',
  'Stop the Septic Slime',
  41
);


SELECT * FROM badHero;  

-- hero - contains only hero data and a foreign key link to mission
DROP TABLE IF EXISTS hero;
CREATE TABLE hero (
  heroID INTEGER PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(50),
  birthday DATE,
  missionID INTEGER
);

INSERT INTO hero VALUES (
  null, 'The Plumber', '1976-10-16', 1);
INSERT INTO hero VALUES (
  null, 'Binary Boy', '1988-1-27', 2);
INSERT INTO hero VALUES (
  null, 'The Janitor', '1964-8-30', 1);

SELECT * FROM hero;

-- view to see age formatted correctly
DROP VIEW IF EXISTS heroAgeView;
CREATE VIEW heroAgeView AS
  SELECT
    name as 'hero',
    CONCAT(
      YEAR(FROM_DAYS(DATEDIFF(NOW(), birthday))),
      ' years, ',
      MONTH(FROM_DAYS(DATEDIFF(NOW(), birthday))), 
      ' months'
    ) AS 'age'
  FROM
    hero;

-- mission table - contains all data relevant to mission
DROP TABLE IF EXISTS mission;
CREATE TABLE mission (
  missionID INTEGER PRIMARY KEY AUTO_INCREMENT,
  description VARCHAR(50),
  villain VARCHAR(30),
  plot VARCHAR(50)
);

INSERT INTO mission VALUES (
  null, 'Stop the septic slime', 
  'Septic Slime Master', 
  'Overcome city with Slime');

INSERT INTO mission VALUES (
  null, 'Make the world safe for Binary representation',
  'Octal', 
  'Eliminate the numerals 8 and 9');

SELECT * FROM mission;

-- standard query for joining hero and mission
SELECT 
  hero.name AS 'hero',
  mission.description AS 'mission'
FROM hero, mission
WHERE
  hero.missionID = mission.missionID;

-- view to store hero / mission query
DROP VIEW IF EXISTS heroMissionView;
CREATE VIEW heroMissionView AS
  SELECT 
    hero.name AS 'hero',
    mission.description AS 'mission',
    mission.villain AS 'villian',
    mission.plot AS 'plot'
  FROM hero, mission
  WHERE
    hero.missionID = mission.missionID;

SELECT * FROM heroMissionView;

-- power - has no foreign keys because it's part of many / many join
DROP TABLE IF EXISTS power;
CREATE TABLE power (
  powerID INTEGER PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(50)
);

INSERT INTO power VALUES(null, 'Sewer snake of doom');
INSERT INTO power VALUES(null, 'unclogging');
INSERT INTO power VALUES(null, 'ability to withstand smells');
INSERT INTO power VALUES(null, 'Hexidecimation Beam');
INSERT INTO power VALUES(null, 'obfuscation');
INSERT INTO power VALUES(null, 'Mighty Mop');

SELECT * FROM power;

-- hero_power is a link table combining hero and power
-- it contains only foreign keys
DROP TABLE IF EXISTS hero_power;
CREATE TABLE hero_power (
  hero_powerID INTEGER PRIMARY KEY AUTO_INCREMENT,
  heroID INTEGER,
  powerID INTEGER
);

INSERT INTO hero_power VALUES (null, 1, 1);
INSERT INTO hero_power VALUES (null, 1, 2);
INSERT INTO hero_power VALUES (null, 1, 3);
INSERT INTO hero_power VALUES (null, 2, 4);
INSERT INTO hero_power VALUES (null, 2, 5);

SELECT * FROM hero_power;

-- The user can't read the hero_power table directly. Use a view
-- to replace keys with fields from the relevant table
SELECT
  hero.name AS 'hero',
  power.name AS 'power'
FROM
  hero, power, hero_power
WHERE 
  hero.heroID = hero_power.heroID
AND
  power.powerID = hero_power.powerID;

-- View to encapsulate hero_power query
DROP VIEW IF EXISTS heroPowerView;
CREATE VIEW heroPowerView AS
  SELECT
    hero.name AS 'hero',
    power.name AS 'power'
  FROM
    hero, power, hero_power
  WHERE 
    hero.heroID = hero_power.heroID
  AND
    power.powerID = hero_power.powerID;

SELECT * FROM heroPowerView;

1 个答案:

答案 0 :(得分:0)

在XAMPP中,您很可能将文档放在htdocs文件夹中......

...除非你为你的应用程序在htdocs下创建了一个子文件夹,否则你会把它放在那里。在大多数情况下,只需将其放在index.php文件所在的位置。

Here is an SO post有一些非常简单的AJAX入门示例。

另外,我不知道你是如何学习的(有些人学习最好的阅读,有些人 - 比如我 - 通过观看),但你听说过phpAcademy吗?大量免费视频可以帮助您前进(如果太忙而无法在观看视频时输入全部内容,则只需支付源代码费用)。我推荐Registration and Login一个用于你正在做的事情,但是上面关于AJAX示例的SO帖子就是你所需要的。