CodeQuery中的JQuery Ajax POST [英] JQuery Ajax POST in Codeigniter
本文介绍了CodeQuery中的JQuery Ajax POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经搜索了很多教程用POST方法,并看到回答了问题,但我的POST仍然不工作...我想我应该发布在这里,如果你们看到的东西,我不! p>
我的js - messages.js:
$(document).ready(function(){
$(#send)。click(function()
{
$ .ajax({
type:POST,
url:base_url +chat / post_action,
data:{textbox:$(#textbox)val()},
dataType:文本,
cache:false,
success:
function(data){
alert(data); //作为调试消息
}
return false;
});
});
我的视图 - chat.php:
<?php $ this-& > js(base_url()。'themes / chat / js / messages.js');?> //我使用大型机框架,这种方式的加载脚本有效
< form method =post>
< input id =textboxtype =textname =textbox>
< input id =sendtype =submitname =sendvalue =Send>
< / form>
上次我的控制器chat.php
//这里有更多的函数
function post_action()
{
if($ _ POST ['textbox '] ==)
{
$ message =您不能发送空文本;
}
else
{
$ message = $ _POST ['textbox'];
}
echo $ message;
}
解决方案
$(document).ready(function(){
$(#send)。click(function()
{
$ .ajax b $ b type:POST,
url:base_url +chat / post_action,
data:{textbox:$(#textbox)。 :text,
cache:false,
success:
function(data){
alert(data); //作为调试信息
}
}); //你错过了这个括号
return false;
});
});
I have searched a lot of tutorials with POST methods and saw answered questions here too but my POST still doesn't work...I thought i should post it here if you guys see something that i don't!
My js - messages.js:
$(document).ready(function(){
$("#send").click(function()
{
$.ajax({
type: "POST",
url: base_url + "chat/post_action",
data: {textbox: $("#textbox").val()},
dataType: "text",
cache:false,
success:
function(data){
alert(data); //as a debugging message.
}
return false;
});
});
My view - chat.php:
<?php $this->load->js(base_url().'themes/chat/js/messages.js');?> //i use mainframe framework which loading script this way is valid
<form method="post">
<input id="textbox" type="text" name="textbox">
<input id="send" type="submit" name="send" value="Send">
</form>
Last My controller - chat.php
//more functions here
function post_action()
{
if($_POST['textbox'] == "")
{
$message = "You can't send empty text";
}
else
{
$message = $_POST['textbox'];
}
echo $message;
}
解决方案
$(document).ready(function(){
$("#send").click(function()
{
$.ajax({
type: "POST",
url: base_url + "chat/post_action",
data: {textbox: $("#textbox").val()},
dataType: "text",
cache:false,
success:
function(data){
alert(data); //as a debugging message.
}
});// you have missed this bracket
return false;
});
});
这篇关于CodeQuery中的JQuery Ajax POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文