2012-07-12 102 views
0

嘿傢伙我沒有收到任何發佈的數據,我非常樂觀,這根本不起作用。最重要的是它發射了一個帶有ID#的接受/拒絕,併爲該表單賦值。我越來越沒有錯誤,也沒有警告,所以我不必通過它加強的問題=(希望另一雙眼睛?阿賈克斯表格提交

對不起的時間提前,我知道我的JQuery的打擊。

<script type="text/javascript" src="http://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 
     google.load("jquery", "1.6"); 
    </script> 

    <script> 
     $(".audit").submit(function() 
      { 
       return false; 
      }); 

     $(".accept, .deny").click(function(event) 
      { 
       $form = $(this).parent("form").get(0); 
       $gruden = $form(function(index) { attributes.push($(this).val());}); 
       $.post($form.attr("action"), $form.serialize() + "&submit=" + $(this).attr("value") + "&gruden=" + $gruden, function(data) { 

       console.log(data); 

      }); 
     }); 
    </script> 

....................... 

<?php foreach($obj->photos as $pending) { ?> 

     <div class='container' id='photo-<?=$pending->id;?>'> 

      <span class='shadow'> 
      <a href='/<?=$pending->large;?>'><img src='http://<?=$_SERVER['HTTP_HOST'].'/'.$pending->small;?>'/></a> 
      </span> 

      <form class='audit' name='audit-<?=$pending->id;?>' action='<?=$_SERVER['PHP_SELF'];?>'> 
      <div class='box'> 

       <ul> 

        <li>ID: <?=$pending->id;?></li> 
        <li>Date: <?=$pending->created_at;?></li> 
        <li>User: <?=$pending->fb_id;?></li> 
        <li>&nbsp;</li> 

        <li> 

         <input class='gruden' value='gruden-<?=$pending->id;?>' type='checkbox' /> 
         <a name='submit' value='accept-<?=$pending->id;?>' class='accept' href=''></a> 
         <a name='submit' value='deny-<?=$pending->id;?>' class='deny' href=''></a> 

        </li> 

       </ul> 

      </div> 
      </form> 

     </div> 

<?php } ?> 
+0

我會建議通過刪除與問題無關的東西來使代碼更小,更易於閱讀(比如CSS,不管標記是不是問題的一部分,也許是PHP呢?) – Jay 2012-07-12 22:00:21

+0

@Jayraj dually注意到 – ehime 2012-07-12 22:03:33

+0

好得多。日Thnx。 :) – Jay 2012-07-12 22:06:30

回答

0

我想我現在看到你的問題。我重寫了你的代碼,所以它更有意義。評論解釋是怎麼回事

<script> 
    $(".audit").submit(function(){ 
      return false; //Preventing the form from submitting if someone hits Enter 
    }); 

    $(".accept, .deny").click(function(event) { 
      var form = $("form.audit"); //Always use var to declare variables in Javascript. It's not PHP; we don't use $, unless you want it to be a part of the variable name. Also fixed your selector 
      var gruden = $form(function(index) { attributes.push($(this).val());}); //Are you trying to find out if the checkbox with class gruden is checked? Please answer in the comments so I can correct this line 
      $.post(form.attr("action") + "&submit=" + $(this).attr("value") + "&gruden=" + gruden, form.serialize(), function(data) { 
        console.log(data); 
      }); //I assume that you want to pass submit and gruden as GET params here, since you're appending them to the URL. If you want them to go as POST vars, then let me know in the comments 
    }); 
</script> 

無意冒犯,但我想你會從中更一點關於JavaScript和jQuery中受益。至少請閱讀jQuery中選擇器的工作方式,以及一些基本的Javascript語法

+0

當我申請'<?php echo $ _SERVER ['PHP_SELF']; ''所以我不認爲這是事實。 – ehime 2012-07-12 22:10:53

+0

表單將不會POST,除非您使用'method ='POST''將它告訴POST,如下所示:'

'。如果您已經這麼做了,請更新您的代碼,這樣就不會有任何誤解,並有利於未來的讀者。 – Jay 2012-07-12 22:13:01

+0

它一直在那裏,因爲我把它縮小了... – ehime 2012-07-12 22:15:22

0

這一行肯定不回你的表單元素,因爲它只是着眼於直接父

$form = $(this).parent("form"); 

嘗試這樣:

$form = $(this).parents("form").get(0);