fear126 Posted July 28, 2016 Share Posted July 28, 2016 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 : Not working for other options sorry for bad english Quote Link to comment https://forums.phpfreaks.com/topic/301673-ajax-not-working-good/ Share on other sites More sharing options...
Solution Barand Posted July 28, 2016 Solution Share Posted July 28, 2016 IDs have to be unique within a document. If you have multiple objects, use classname instead. Quote Link to comment https://forums.phpfreaks.com/topic/301673-ajax-not-working-good/#findComment-1535233 Share on other sites More sharing options...
fear126 Posted July 28, 2016 Author Share Posted July 28, 2016 oh ok thanks i didnt get that in mind ill give it a try thanks for help Quote Link to comment https://forums.phpfreaks.com/topic/301673-ajax-not-working-good/#findComment-1535234 Share on other sites More sharing options...
fear126 Posted July 28, 2016 Author Share Posted July 28, 2016 IDs have to be unique within a document. If you have multiple objects, use classname instead. thanks it worked like a charm Quote Link to comment https://forums.phpfreaks.com/topic/301673-ajax-not-working-good/#findComment-1535235 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.