I have this ajax jquery code:
var form = document.getElementById('frm');
var data_string = form.serialize();
$.ajax({
type: "POST",
url: "my_php_file.php",
data: data_string,
success: function(data) {
}//end success function
}) //end ajax call
This is in an external file called ajax.js.
I include ajax.js into an html file called “show.html”.
I also include jquery.js into show.html
I have tried getting the serialize to work, but the code is terminated right before executing the serialize.
I have no idea why. But I am sure that it is the serialize which is causing it.
Is it possible to make some easy modification to this, so it doesn’t use serialize?
Thanks
UPDATE:
This code (from answer below) seems to work partially also, when I alert the “form” variable, the message says “HTML Form Object” so it finds the form.
Then when I alert the “data_string” variable, the message says “frm=undefined”.
Any ideas why?
var form = document.getElementById('frm');
var data_string = $(form).serialize();
The
serialize()method comes from jQuery. Your statement is failing because form isn’t wrapped in jQuery:Or: