doushi1847 2011-06-16 19:33
浏览 45

AJAX调用PHP页面,需要帮助

I'm not sure if I have done right when I use AJAX to send some info to a PHP-page with some code that connects to a database and stores a piece of text. A PHP-page that AJAX call, must that PHP-page be different compared to a common PHP-page? It's not working, I get a 404 Not Found message?

Here is the PHP-page:

<?php
session_start();
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

$replyArticleId = isset($_POST['replyArticleId']) ? $_POST['replyArticleId'] : '';
$replyText = isset($_POST['replyText']) ? $_POST['replyText'] : '';

$replySign = $_SESSION['accountId'];

date_default_timezone_set("Europe/Stockholm");
$date = new DateTime();
$replyDate = $date->format('Y-m-d H:i:s');

$tableUser = DB_PREFIX . WS_DB_USER;
$tablePost  = DB_PREFIX . WS_DB_POST;
$tableComment = DB_PREFIX . WS_DB_COMMENT;
$tableArticle = DB_PREFIX . WS_DB_ARTICLE;
$tableReply = DB_PREFIX . WS_DB_REPLY;

// Add new comment

$query1 = "INSERT INTO {$tableReply} (replyArticleId, replyText,replyUserId,        
replyDate) VALUES    ('{$replyArticleId}','{$replyText}','{$replySign}',  '{$replyDate}');";
$query2 = "UPDATE {$tableArticle} SET articleDateUpdated = NOW() WHERE articleId =     {$replyArticleId};";
$res = $mysqli->query($query1) or die($mysqli->error);
$res = $mysqli->query($query2) or die($mysqli->error);

$mysqli->close();

This is the AJAX code that I use to call and send some test content:

$.ajax({
url: "PAddReplyProcessAJAX.php?replyArticleId=1", 
type: "POST",
dataType: "text",
data: "replyText=" + "test"
}); 



?>
  • 写回答

3条回答 默认 最新

  • dpxo13079 2011-06-16 19:38
    关注

    Is that really the URL you want to use PAddReplyProcessAJAX.php? Is it in the same directory as the page you're calling the ajax from?

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题