Print the result of an AJAX query in an input text

0

I usually print an AJAX response on a div or span. My question is if I can make my result show in an input text.

Example:

$(document).ready(function() {
    $('#form, #foo').submit(function() {
        $.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            data: $(this).serialize(),
            success: function(data) {
                $('#result').html(data);
            }
        });       
        return false;
    });
});

After my success my result is on a div.

Can I change to an input text within a form?

    
asked by Ever 28.06.2017 в 16:56
source

1 answer

2

As simple as getting the input with jquery and doing a .val (data)

$(document).ready(function() {
    $('#form, #foo').submit(function(event) {
        event.preventDefault();
        $.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            data: $(this).serialize(),
            success: function(data) {
                $('#miInput').val(data);
            }
        });       
       return false;
   });
});
    
answered by 28.06.2017 / 17:00
source