Przeszukałem wiele samouczków metodami POST i widziałem odpowiedzi na te pytania również tutaj, ale mój POST nadal nie działa ... Pomyślałem, że powinienem opublikować to tutaj, jeśli zobaczycie coś, co daję "t!JQuery Ajax POST w Codeigniter
Moi 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;
});
});
Moim zdaniem - 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>
Ostatni Mój kontroler - chat.php
//more functions here
function post_action()
{
if($_POST['textbox'] == "")
{
$message = "You can't send empty text";
}
else
{
$message = $_POST['textbox'];
}
echo $message;
}
czy dostaję jakieś błędy .. proszę sprawdzić konsolę narzędzi programistycznych – bipen
czy to będzie kontroler? jaki błąd rzuca? –
gdzie definiujesz 'url: base_url', uważam, że to twój problem. – Boris