• Recent Questions
  • Popular Questions

jQuery load php file (and send a value)?

Trying to load insert.php?id=#### into a div on the page

#### is a number that is from a form here’s my code:

The form:

ID: <input class="text" type="text" name="ID" value="” />

jQuery stuff:
$(document).ready(function(){
$(“#Add_Form”).submit(function() {
var ID = $(‘#ID’).attr(‘value’);
$(“#Add_Load”).get(“insert.php”, { “ID”: ID } );
return false;
});
});

    Chris G
    Posted 1 year ago

    The $.get() method in jQuery isn’t used on elements, as you’re trying to do with:

    “$(“#Add_Load”).get(“insert.php”, { “ID”: ID } );”

    It is actually used to load a remote page using an HTTP GET request, in the form:

    $.get( url, [data], [callback], [type] )

    Where data is your form data, and callback is the function to do something with the returned data.

    In your case, try something like this:

    $(document).ready(function(){
    $(“#Add_Form”).submit(function() {
    var ID = $(‘#ID’).attr(‘value’);
    $.get(“insert.php”, { “ID”: ID },
    function(data){
    $(“#Add_Load”).html(data);
    });
    return false;
    });
    });

Answer this Question :

You must be logged in to post an answer. Signup Here, it takes 5 seconds :)

Other Questions