By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,625 Members | 1,497 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,625 IT Pros & Developers. It's quick & easy.

How Ajax can handle the on click event on button.

P: 4
i had a website with 2 drop down list and a few buttons depending on the selected item on the drop down list.
For example i had a home page index.php and i had another two pages getBrand.php and getModel.php so the first drop down list i would need to choose which brand of mobile phone i wanted and then on the 2nd drop down list, a list of model of the mobile phone provided by the selected brand will be shown, everything is work fine until when u select the model, the features of the model will be shown in a form of table with a few buttons for users to click, like after clicking button A some data will be transfer to another page via GET method, after processing the data, the home page will show the data to the user. How can it be done?
Mar 7 '12 #1
Share this Question
Share on Google+
1 Reply


P: 4
This the code not sure how to continue it so that after i click the button some data will be passed to another page via GET method then the page will send the processed data back.
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.                 var quot = ' " ';
  3.                 function display(a){
  4.                     alert("'" + a + "'")
  5.                 }
  6.                 $(document).ready(function() {
  7.  
  8.                     $("#1").change(function() {
  9.                         $("#pageheader").html("Access Point Finder : "+ $(this).find(":selected").text());
  10.                         $.ajax({
  11.                             type: "GET",
  12.                             url: "getShops.php",
  13.                             data: "location=" + $(this).find(":selected").val(),
  14.                             cache: false,
  15.                             success: function(msg){
  16.                                 $("#shop").empty();
  17.                                 my_shop_array = $.parseJSON(msg);
  18.                                 for (i = 0; i < my_shop_array.length; i ++) {
  19.                                     $("#shop").append('<option value="' + my_shop_array[i].shop + '">' + my_shop_array[i].shop + '</option>');
  20.                                 }
  21.                                 $("#shop").trigger('change');
  22.                             }
  23.                         });
  24.                     });
  25.  
  26.                     $("#shop").change(function() {
  27.                         $.ajax({
  28.                             type: "GET",
  29.                             url: "getApv2.php",
  30.                             data: "shop=" + $(this).find(":selected").val(),
  31.                             success: function(msg){ 
  32.                                 $('#ap').empty();
  33.                                 my_response_array = $.parseJSON(msg)
  34.                                 $("#ap").append("<th> Access Point Name </th><th> Controller IP </th><th> Remark </th><th> Access Point Status </td><th> Router Status </th><th> Contoller Status </th>");   
  35.                                 for ( i = 0; i < my_response_array.length; i++){ 
  36.                                     $("#ap").append("<tr><td>" + my_response_array[i].name + "</td>\n\
  37.                                 <td><a href = 'https://" + my_response_array[i].ip +"/' target='_blank'>"+my_response_array[i].ip+"</a></td>\n\
  38.                                 <td>"+my_response_array[i].description+"</td>\n\
  39.                                 <td><button type='button' onClick='display()'>Ping</button></td>\n\
  40.                                 <td><button type='button' onclick='display()'>Ping</button></td>\n\
  41.                                 <td><button type='button' onclick='display()'>Ping</button></td>\n\
  42.                                 </tr>");
  43.                                                     }
  44.                                                 }   
  45.                                             });
  46.                                         });
  47.  
  48.                                         $("#1").trigger('change');
  49.                                     });
  50.         </script>
Mar 7 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.