我正在尝试将一些数据发送到PHP文件,但jQuery甚至不运行我的PHP文件。只是为了测试我回应一些文字,但我看不到任何输出。这是我的代码:
jquery:
.
.
.
$("#addFolder").click(function(){
$(".folders").append("<p class='folder'>This is first folder<input type='checkbox' name='checkFolder'></p>");
$data = {'id':document.getElementById('id').value, 'text':document.getElementById('text').value};
$.post('addFolder.php', $data);
});
addFolder.php:
<?php
include 'connect.php';
include 'functions.php';
$id = $_POST['id'];
$text = $_POST['text'];
session_start();
$user = $_SESSION['user'];
$userID = mysql_query("select id from users where username = '$user'")
$iduser = mysql_result($userID, 0)
mysql_query("insert into users_folders values ('$iduser', '$id') where id = '$iduser'") or die(mysql_error());
?>
答案 0 :(得分:4)
$.post('addFolder.php', data);
应该是
$.post('addFolder.php', $data);
传递参数data
addFolder.php
以下行中的问题:
mysql_query("insert into users_folders values ('$iduser', '$id')
where id = '$iduser'") or die(mysql_error());
答案 1 :(得分:1)
检查这个
$.post('addFolder.php', data);
//data replace $data like => $.post('addFolder.php', $data);
所以现在
$("#addFolder").click(function(){
$(".folders").append("<p class='folder'>This is first folder<input type='checkbox' name='checkFolder'></p>");
$data = {'id':document.getElementById('id').value, 'text':document.getElementById('text').value};
$.post('addFolder.php', $data);
});