Jump to content

Ajax not working good


Go to solution Solved by Barand,

Recommended Posts

Hi i am having trouble with my ajax code.

It take 1st result data-id data and post to other page but it not doing that for all but there is all created exact same using foreach loop.

Here is code and images

 


foreach ($companySystem->getAllCompanyGroups($companySystem->getAllCompanyData()->id) as $value) {
                                          if(System::checkOddEvent($srNo) == true){
                                            echo "
                                            <tr class='odd gradeX'>
                                                  <td>$srNo</td>
                                                  <td>".System::removeUnderscore($value->groupName)."</td>
                                                  <td>$value->createdDate</td>
                                                  <td class='center'>$value->createdBy</td>
                                                  <td class=''>
                                                  <button type='button' id='cmpEditBtn' class='btn btn-warning' data-id='".$value->id."' data-toggle='modal' data-target='#editCompanyGroup'><span class='fa fa-edit fa-large'></span> Edit</button>
                                                  <button type='button' class='btn btn-danger' data-toggle='modal' data-target='#removeCompanyGroup'><span class='fa fa-ban'></span> Remove</button>
                                                  </td>
                                              </tr>
                                          ";
                                          }else{
                                            echo "
                                            <tr class='even gradeX'>
                                                  <td>$srNo</td>
                                                  <td>".System::removeUnderscore($value->groupName)."</td>
                                                  <td>$value->createdDate</td>
                                                  <td class='center'>$value->createdBy</td>
                                                  <td class=''>
                                                  <button type='button' id='cmpEditBtn' class='btn btn-warning' data-id='".$value->id."' data-toggle='modal' data-target='#editCompanyGroup'><span class='fa fa-edit fa-large'></span> Edit</button>
                                                  <button type='button' class='btn btn-danger' data-toggle='modal' data-target='#removeCompanyGroup'><span class='fa fa-ban'></span> Remove</button>
                                                  </td>
                                              </tr>
                                          ";
                                          }
                                          $srNo++;
                                        }

 

Ajax :



<script>
         $('#cmpEditBtn').on('click',function(e){
               $.ajax({
               type:'POST',
               url :"editCompanyGroupAjax.php",
               data: "id="+ $(this).attr('data-id'),
               dataType: 'json',
               success: function(data) {
                   $("#previousCmpName").val(data.groupName);
               },
               error:function(exception){alert('Exeption:'+exception);}
            }); 
             e.preventDefault();
            });
    </script>


Images :

All working fine if i click on first edit button :

working.png

 

Not working for other options

notworking.png

 

sorry for bad english

Link to comment
https://forums.phpfreaks.com/topic/301673-ajax-not-working-good/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.