以下に、DBにいくつかのエントリを追加するために使用するjQueryがあります。正常に動作しています。同じファイル内の同じファイルを使用してデータを削除します。 削除-から-DBの形式は、ID RemoveMe
があり、フォームID AddMe
でアドオンに-DBスクリプトを見ることができるの下には$.post("add-to-db.php?id=<?php echo (int)$_GET['id'] ?>"
2つの同一のjQueryスクリプトを1つにマージするには?
にポストします。
私の質問は、これら2つを1つにする方法があるかどうかです。ありがとうございました。
$(function(){
$("#AddMe").submit(function(e){
e.preventDefault();
$.post("add-to-db.php?id=<?php echo (int)$_GET['id'] ?>", $("#AddMe").serialize(), function (data){
$("#submit").attr('src','http://download.oracle.com/tech/blaf/specs/buttons/actnavbuttons/actnav_disabled_example.gif');
$("#submit").attr('disabled',true);
$("#submit").unbind('click');
$("#message_post").html("Thank you");
setTimeout(function() { $("#message_post").hide(); window.location.href = "product.php?id=<?php echo (int)$_GET['id'] ?>"; }, 2000);
});
});
});
<form id="AddMe">
<input type="image" name="submit" id="submit" src="http://blog.mirthlab.com/wp-content/uploads/2008/04/rollover-up.png">
</form>
<div id="message_post"></div>
$(function(){
$("#RemoveMe").submit(function(e){
e.preventDefault();
$.post("remove-from-db.php?id=<?php echo (int)$_GET['id'] ?>", $("#RemoveMe").serialize(), function (data){
$("#submit").attr('src','http://download.oracle.com/tech/blaf/specs/buttons/actnavbuttons/actnav_disabled_example.gif');
$("#submit").attr('disabled',true);
$("#submit").unbind('click');
$("#message_post").html("Thank you");
setTimeout(function() { $("#message_post").hide(); window.location.href = "product.php?id=<?php echo (int)$_GET['id'] ?>"; }, 2000);
});
});
});
<form id="RemoveMe">
<input type="image" name="submit" id="submit" src="http://blog.mirthlab.com/wp-content/uploads/2008/04/rollover-up.png">
</form>
<div id="message_post"></div>
IDとURLのペアを格納するオブジェクトリテラルの配列を使用することができますが、これは最適なソリューションですか? – asotshia