私は、ユーザーがコースから学生を追加/削除できるようにする小さなアプリケーションを構築しています。コースを追加/削除するたびに、データベースが更新され、ユーザーのコースの総数が更新されます。私はコースに学生を追加するとき、それは正常に動作しますが、私はそれらを削除するために私は0(私のPHPモデル関数から)返されます。私はそれがjqueryの問題かもしれないと思う、私は私がクローンを使用する必要があると思う?だから、このような長い記事を残念に思っているだけで、みんなが見るための十分なコードを持っていることを確認したかったのです。ここ はコースにユーザーを追加し、削除し、私のjQueryのコードです:ここで要素を追加/削除し、属性をAJAX経由で更新する
function addUserToClass(user)
{
//creates the a data string to send to the controller with the user's id and the course id
var postString = "courseid="+$("#course option:selected").val()+"&uid="+user.find('input').val();
//adds the user to the course list in the database
$.post('index.php/admin/addUserToCourse',postString);
$("#courseList").append(user);
$('#courseList .addUser').text('(-)').removeClass('addUser').addClass('removeUser');
}
//removes a user from the selected course in the database as well as on the screen
function removeUserFromClass(user)
{
var postString = "courseid="+$("#course option:selected").val()+"&uid="+user.find('input').val();
//removes the user fromt the course in the database
$.post('admin/removeUserFromCourse',postString);
$(user).remove();
$('#usertable').append(user);
$('#usertable .removeUser').text('(+)').removeClass('removeUser').addClass('addUser');
}
は、彼らがしているコース数を更新している私のjQueryのです:
function updateUserCourses(uid)
{
var postString = 'uid='+uid.siblings(':input').val();
$.post('index.php/admin/getUsersCourses', postString , function(data){
data = jQuery.parseJSON(data);
uid.siblings('.internalCounter').text(data.internal);
uid.siblings('.externalCounter').text(data.external);
})
}
ないあなたがこれを必要とする場合は必ずしかし、呼び出されて、私のPHP(CodeIgniterのコントローラ)は、次のとおりです。
function getUsersCourses()
{
$this->load->model('course_model');
$courses = $this->course_model->getUsersCourses($_POST['uid']);
echo json_encode($courses);
}
そして、私のモデル関数:
function getUsersCourses($uid)
{
$external = array();
$internal = array();
$final = array();
//Selects all of the courses the user has been added to
$usersCourses = $this->db->query("SELECT courseid FROM final_course_list WHERE uid='{$uid}'");
//If they have courses, proceed to process them
if ($usersCourses->num_rows() > 0)
{
//For every course they have, we get the category of the course
foreach($usersCourses->result() as $row)
{
$courseCat = $this->db->query("SELECT category FROM courses WHERE id = '{$row->courseid}'")->row_array();
if($courseCat['category'] == 'External Topics')
{
array_push($external, $courseCat);
}
else if($courseCat['category'] == 'Internal Topics')
{
array_push($internal, $courseCat);
}
}
//adds the internal and external amount of classes to one array
$final['internal'] = count($internal);
$final['external'] = count($external);
$result = $final;
}
else
{
$result = 0;
}
return $result;
}
配列を返すために必要な0を返すので、私がチェック倍増し、その正しい名前、私は(ここに記載されていない)イベントリスナーに)(removeUserFromClassを呼び出します。あなたの助けを借りて、私の矛盾した命名規則を指摘してください。 – dan
@dan:あなたのURLに 'index.php /'がありません。これは今解決されていますか? – ifaour
私は500のエラーを与えていたindex.phpが不足していましたが、私はそれを修正しましたが、まだ更新していません。私はまだ私のモデルから来ているように見える私に戻って0を得るすべてのクエリの結果を思い付くことはありません。 – dan