Get value from a specific input using AJAX

1

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

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

This value of the ID is in a hidden field of the form, how can I get this value and move to ajax? example 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;
    });
}); 
    
asked by anonymous 15.11.2016 / 00:28

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;
    });
}); 
    
15.11.2016 / 01:10