0

I'm loading some stuff from a php page using AJAX. this works fine.

but now I need to get the elements (button or form or div) loaded using AJAX.

My current code that doesn't work is this:

jQuery(document).ready(function() {


$(function(){   
    $('.delForm').on('submit', function(dleItem){


        // prevent native form submission here
        dleItem.preventDefault();

        // now do whatever you want here


        $.ajax({
            type: $(this).attr('method'),// <-- get method of form
            url: $(this).attr('action'),
            //url: "cart.php",
            data: $(this).serialize(), // <-- serialize all fields into a string that is ready to be posted to your PHP file
            beforeSend: function(){

            },
            success: function(data){

            }
        });
    });


    });
  });

I tried to do something like this:

document($('.delForm')).on('submit', function(dleItem){

and this:

body($('.delForm')).on('submit', function(dleItem){

but this will stop my code working.

could someone please advise on this issue?

Thanks in advance.

TERO
  • 159
  • 2
  • 16
  • There are not `document()` or `body()` methods unless you wrote one or included some library. You also have a ready method wrapped in a ready method. Makes no sense. `jQuery(document).ready(function(){})` is the same thing as `$(function(){})` – epascarello Mar 31 '15 at 13:27

1 Answers1

2

Use

$(document).on('submit', '.delForm', function(dleItem) {});
D4V1D
  • 5,805
  • 3
  • 30
  • 65