0

少しずつ、私が取り組んでいるPHP WebアプリをJquery AJAXフォーム送信に変換してきました。

私が取り組んでいる現在のものは、テーブルの行を削除するためのものです。return false;. _ これは、オブジェクトを作成するフォームの問題でしたが、このサイトの助けのおかげで、それがソートされ、完全に機能するようになりました。

これが私のJavaScriptです:

$("form#table_customer").submit(function() {
        var query_string = 'page=customer&rows=';

        $(":checked").each(function() {
            query_string += this.value + "-";
        });

        $.ajax({
            url: "inc/deletesql.php",
            type: "POST",
            data: query_string,
            cache: false,
            success: function(data){
                $('#maincontent').load('inc/showObjects.php?o=customer');
            }
        });
        return false;
    });

PHP ファイル (deletesql.php) は、通常の POST 送信で機能します。しかし、ajaxを介してデータを投稿してもうまくいかないようです。

http://www.sfyfe.com/studioadmin/index.php?i=customerでコンテキストで確認できます

4

1 に答える 1

0
    $('#maincontent').load('inc/showObjects.php?o=customer');
    ...
    // at this point form#table_customer doesn't exist yet in the DOM
    // so this binding a handler will give no effect
    $("form#table_customer").submit(function() {
           ....
    });

代わりにこれを試してください:

 // make the load reusable

 function addDeleteHandler() {
     // handle the load event
     // attach the event handler everytime the content is loaded, 
     // and the form#table_customer is added to the dom
     $('#maincontent').load('inc/showObjects.php?o=customer', function() {
         $("form#table_customer").submit(function() {

             var query_string = 'page=customer&rows=';

             $('input[name="checkbox"]:checked').each(function() {
                query_string += this.value + "-";
             });

             $.ajax({
                 url: "inc/deletesql.php",
                 type: "POST",
                 data: query_string,
                 cache: false,
                 success: function(data){
                   addDeleteHandler();
                 }
             });

             return false;
          });
      });
  }

  addDeleteHandler();
于 2012-08-28T02:34:46.920 に答える