AJAX と JSON を使用したデータの読み込みに問題があります。
登録ボタンを押すと、永遠にロードし続けます...
AJAX コード
$(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);
}
データを取得するコントローラー
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');
}
}
jsonを与えるための私のヘルパー関数
function msg($status,$txt)
{
return '{"status":'.$status.',"txt":"'.$txt.'"}';
}
Codeiginter は JSON に追加のものを使用していますか、それとも重要なものが本当に欠けていますか?