注入 AJAX MooTools 响应
我有一个表单,用户将在其中输入文本,当他提交表单时,我认为必须注入我想要的文本,或者像 AJAX 注释一样简单地附加到页面,但我的问题是我可以在页面。
我已经测试了代码的工作(我已经警告了消息和其他内容)。
这是我的代码:
en4.questionanswer = {
postAnswer : function() {
var mess = $('a_mess');
var user_id = $('q_user_id');
var question_id = $('question_id');
//check if value is blank
//post Question
var request = new Request.JSON({
'method' : 'post',
'url' : en4.core.baseUrl + 'question/postans',
'data' : {
'mess' : mess.value,
'question_id' : question_id.value
},
'onComplete':function(responseObject) {
if( typeof(responseObject)!="object") {
//alert('ERR');
}
else {
if (responseObject.result == "success") {
mess.value=''; //clear text after submiting
// en4.questionanswer.start("1");
alert(responseObject.answer);
}
else {
alert(responseObject.message);
}
}
}
});
request.send();
}
});
在 PHP 部分我有:
echo json_encode(array("result" => "success",
"message" => "Post message successful!",
"answer" => $content));
I have a form where the user will input a text and when he submits the form, the text I want must be injected, I think, or simply attached to the page like AJAX comments, but my problem is that I can get the message on the page.
I have the code working tested (I have alert the message and other stuff).
Here's my code:
en4.questionanswer = {
postAnswer : function() {
var mess = $('a_mess');
var user_id = $('q_user_id');
var question_id = $('question_id');
//check if value is blank
//post Question
var request = new Request.JSON({
'method' : 'post',
'url' : en4.core.baseUrl + 'question/postans',
'data' : {
'mess' : mess.value,
'question_id' : question_id.value
},
'onComplete':function(responseObject) {
if( typeof(responseObject)!="object") {
//alert('ERR');
}
else {
if (responseObject.result == "success") {
mess.value=''; //clear text after submiting
// en4.questionanswer.start("1");
alert(responseObject.answer);
}
else {
alert(responseObject.message);
}
}
}
});
request.send();
}
});
In the PHP part I have:
echo json_encode(array("result" => "success",
"message" => "Post message successful!",
"answer" => $content));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果responseObject.answer是您尝试放置在页面中的答案,这将帮助您开始。
将 onComplete 函数中的警报(responseObject.answer)替换为:
将 $(document.body) 替换为您想要的任何选择器例如:
或者
您的帖子中提供的信息非常有限,所以如果我错过了标记,我深表歉意,只是尝试为您指明正确的方向。
If responseObject.answer is the answer you are trying to place in the page this will get you started.
replace the alert(responseObject.answer) in the onComplete function with:
Replace $(document.body) with any selector you would like example:
or
The information provided in your post was very limited so if I missed the mark I apologize, just trying to point you in the right direction.