I have problem loading data with AJAX and JSON.
If I hit register button, it keeps loading forever...
AJAX code
$(document).ready(function(){
$('#regForm').submit(function(e) {
register();
e.preventDefault();
});
});
function register()
{
hideshow('loading',1);
error(0);
$.ajax({
type: "POST",
url: "http://yoursitename.com/register/submit_registration",
data: $('#regForm').serialize(),
dataType: "json",
success: function(msg){
if(parseInt(msg.status)==1)
{
window.location=msg.txt;
}
else if(parseInt(msg.status)==0)
{
error(1,msg.txt);
//alert(msg);
}
hideshow('loading',0);
}
});
}
function hideshow(el,act)
{
if(act) $('#'+el).css('visibility','visible');
else $('#'+el).css('visibility','hidden');
}
function error(act,txt)
{
hideshow('error',act);
if(txt) $('#error').html(txt);
}
The controller, where we take data
public function submit_registration() {
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $this->input->post("name");
if(!$name) {
die(msg(0, "Please insert Your name!"));
}
echo msg(1, "index.html");
} else {
exit('No direct script access allowed');
}
}
My helper function, to give the json
function msg($status,$txt)
{
return '{"status":'.$status.',"txt":"'.$txt.'"}';
}
Is Codeiginter using some extra stuff for JSON or I'm really missing something important?