所以我是新来的ajax,我面临一个问题,从我的窗体获取所有值。传递ajax数组到数据:
所以我想插入名称reply_txt和$ NewSID的,以我的表
HTML表单:
<form>
<input type="hidden" name="replyToPost" value="<?php echo $newsId;?>">
<textarea name="reply_txt" class="replyText"></textarea>
<button class="replySubmit">Answer</button>
</form>
AJAX:我思我必须在某种方式传递一个数组中的数据:replyData
$(".replySubmit").click(function(event){
event.preventDefault();//prevent action from button
var replyData = 'reply_txt='+ $(".replyText").val(); //build a post data structure
$.ajax({
type: "POST", // POST type
url: "response.php", //call ajax on page
dataType:"text", //type of data html/ajax/jason ...
data:replyData, //Form variables intups
success:function(response){
$(".respondsReply").append(response);
$(".replyText").val(''); //empty text field on successful
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
response.php:错误是不确定的变量$ NewSID的
if(isset($_POST["reply_txt"]) && strlen($_POST["reply_txt"])>0){
$replyToSave = filter_var($_POST["reply_txt"],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
$newsId = $_POST["replyToPost"];
$userId = $_SESSION['userId'];
$reply_row = $db->query("INSERT INTO replyPost(message,newsId_fk,userId_fk) VALUES('$replyToSave','$newsId','$userId')");
}
你不是每个人都在php –
中每个出了什么东西?什么?我只想插入到我的表中,但我需要它在数据中:我认为 – user3426191
对不起,我用.each()编程,所以我对此感到困惑..我的意思是回声出来..你应该在PHP中回应出来的东西获得成功的反应功能 –