Get value from a specific input using AJAX

Asked

Viewed 2,319 times

1

Next, I have a form that will be sent with AJAX, but the URL will vary according to the ID, example:

site.com/ajax/remove/100 <- ID
site.com/ajax/remove/200 <- ID

This ID value is in an Hidden field of the form, how can I take this value and pass to ajax? example of the code:

jQuery(document).ready(function() {
    jQuery('#send_request').submit(function() {

        var dados = jQuery(this).serialize();
        //var id = 

        jQuery.ajax({

            url : 'site.com/'+id,
            dataType : 'JSON',
            type : "POST",
            data : dados,
            success : function(response) {
                //alert(response.message);
                if (response.success == 1) {
                    //tudo ok
                } else {
                    //deu ruim,zé
                }
            }
        });
        return false;
    });
}); 

1 answer

4


jQuery(document).ready(function() {
    jQuery('#send_request').submit(function() {

        var dados = jQuery(this).serialize();
        var id = $("#campo-hidden").val(); /// <<<<<

        jQuery.ajax({

            url : 'site.com/'+id,
            dataType : 'JSON',
            type : "POST",
            data : dados,
            success : function(response) {
                //alert(response.message);
                if (response.success == 1) {
                    //tudo ok
                } else {
                    //deu ruim,zé
                }
            }
        });
        return false;
    });
}); 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.