データベースにクエリを実行してオンまたはオフにする簡単なチェックボックスがあります。ユーザーはこの値を変更でき、私はを介してリクエストを送信しajax
ます。URLはJoomlaコンポーネントであるため、風変わりです(この質問では重要ではありませんが、念のため)。
$(function() {
$("#iButton").iButton();
$('#iButton').change(function() {
var checkedLength = $(this + ':checked').length;
if(1 == checkedLength){
$.ajax({
url: 'index.php?option=com_mycomponent&task=globaldetection&id_hash=<?php echo $id_hash; ?>&global_monitoring='+checkedLength+'&format=raw'
});
} else {
$.ajax({
url: 'index.php?option=com_mycomponent&task=globaldetection&id_hash=<?php echo $id_hash; ?>&global_monitoring='+checkedLength+'&format=raw'
});
}
});
});
<?php
//highlight whether the checkbox is on or off
if ($userstatus == "ENABLED") //get this value from server
{
//turned on
$global_monitoring = "checked=\"checked\"";
}
else
{
$global_monitoring = "";
}
?>
<div class="dropshadow">
<p id="iButtontext">
<input type="checkbox" id="iButton" <?php echo $global_monitoring; ?> name="iButton_checkbox" />
</p>
</div>
これは正常に機能し、期待どおりですが、ここでいくつか質問があります。
ajax
条件に応じて関数を2回複製します。これを行うためのより良い方法または完全に受け入れられる方法はありますか?- URLのみを渡し、他の設定は渡しません。私はいつも
success
この設定を使用しましたが、この場合、他に行う必要のある応答はありません。私はそれがオプションであることを知っていますが、その時点で何か他のことをする必要がありますか? - ajaxに渡す必要がある他の設定はありますか?それも...シンプルに思えます。
任意のガイダンスをいただければ幸いです。ありがとう。