How Ajax can handle the on click event on button.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • summer law
    New Member
    • Mar 2012
    • 4

    How Ajax can handle the on click event on button.

    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?
  • summer law
    New Member
    • Mar 2012
    • 4

    #2
    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.
    Code:
    <script type="text/javascript">
                    var quot = ' " ';
                    function display(a){
                        alert("'" + a + "'")
                    }
                    $(document).ready(function() {
                 
                        $("#1").change(function() {
                            $("#pageheader").html("Access Point Finder : "+ $(this).find(":selected").text());
                            $.ajax({
                                type: "GET",
                                url: "getShops.php",
                                data: "location=" + $(this).find(":selected").val(),
                                cache: false,
                                success: function(msg){
                                    $("#shop").empty();
                                    my_shop_array = $.parseJSON(msg);
                                    for (i = 0; i < my_shop_array.length; i ++) {
                                        $("#shop").append('<option value="' + my_shop_array[i].shop + '">' + my_shop_array[i].shop + '</option>');
                                    }
                                    $("#shop").trigger('change');
                                }
                            });
                        });
    
                        $("#shop").change(function() {
                            $.ajax({
                                type: "GET",
                                url: "getApv2.php",
                                data: "shop=" + $(this).find(":selected").val(),
                                success: function(msg){ 
                                    $('#ap').empty();
                                    my_response_array = $.parseJSON(msg)
                                    $("#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>");   
                                    for ( i = 0; i < my_response_array.length; i++){ 
                                        $("#ap").append("<tr><td>" + my_response_array[i].name + "</td>\n\
                                    <td><a href = 'https://" + my_response_array[i].ip +"/' target='_blank'>"+my_response_array[i].ip+"</a></td>\n\
                                    <td>"+my_response_array[i].description+"</td>\n\
                                    <td><button type='button' onClick='display()'>Ping</button></td>\n\
                                    <td><button type='button' onclick='display()'>Ping</button></td>\n\
                                    <td><button type='button' onclick='display()'>Ping</button></td>\n\
                                    </tr>");
                                                        }
                                                    }   
                                                });
                                            });
    
                                            $("#1").trigger('change');
                                        });
            </script>
    Last edited by Dormilich; Mar 7 '12, 09:06 PM. Reason: Please use [CODE] [/CODE] tags when posting code.

    Comment

    Working...