user5473154 user5473154 - 4 months ago 15
jQuery Question

jquery, node - more than one get request

I am trying to add another get request.

In my html

$(document).ready(function(){
$("#submit-button-one").click(function(){
var searchField = $("#searchField").val();
$.get("http://localhost:3000/searching", {
searchField: searchField
}, function(data){
// display results and reveal submit-button-two
});
});

$("#submit-button-two").click(function(){
var selectedItem = $('input[name = item]:checked').val();
alert(selectedItem);

// ^everything above works without the code below

$.get("http://localhost:3000/submit-item", {
selectedItem: selectedItem
}, function(data){
alert(data);
}
});
});


When I add in the code for the second get request, the first one stops working and clicking submit-button-one doesn't do anything anymore.

Any help/links would be great! thanks

Answer

You're missing a parenthesis on the last $.get.

$(document).ready(function(){
    $("#submit-button-one").click(function(){
        var searchField = $("#searchField").val();
        $.get("http://localhost:3000/searching", {
            searchField: searchField
        }, function(data){
            // display results and reveal submit-button-two
        });
    });

    $("#submit-button-two").click(function(){
        var selectedItem = $('input[name = item]:checked').val();
        alert(selectedItem);

        // ^everything above works without the code below

        $.get("http://localhost:3000/submit-item", {
            selectedItem: selectedItem
        }, function(data){
            alert(data);
        });
    });
});
Comments