gpt4 book ai didi

codeigniter - Codeigniter 中的 JQuery Ajax POST

转载 作者:行者123 更新时间:2023-12-03 22:12:37 25 4
gpt4 key购买 nike

我已经搜索了很多有关 POST 方法的教程,也在这里看到了问题的答案,但我的 POST 仍然不起作用...我想如果你们看到了我没有看到的东西,我应该将其发布在这里!

我的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;
});
});

我的观点 - 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>

最后我的 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;
});
});

关于codeigniter - Codeigniter 中的 JQuery Ajax POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17590688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com