Marverick M. Marverick M. - 11 months ago 56
jQuery Question

loading .php file into textbox using ajax

Hi there good day to you Maam/Sir.
I have a problem with my textbox field which is that I can't load the file in the textbox but I can load it in div

I have this code bellow

$(document).ready(function(e){
$.ajaxSetup({cache:false});
setInterval(function(){$('#name').load('name.php');}, 1500);
});

<input type="text" name="name" id="name"/>


I can't determine what is the problem there. Thank you so much for helping me.

Answer Source

jQuery's .load() loads data from the server and inserts the returned HTML into an element. An <input /> element is not one you can insert HTML into; instead you will need to give it a value by adjusting it's value attribute.

Try something like this instead:

$(document).ready(function(e){
    $.ajaxSetup({cache:false});
    setInterval(function() {
        $.get('name.php', function (data) {
            $('#name').val(data);
        });
    }, 1500);
});