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();
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();
Share
Improve this question
edited Nov 23, 2010 at 16:33
asked Nov 23, 2010 at 14:43
user188962user188962
1
- be.twixt.us/jquery/formSubmission.php ajaxSubmit plugin does ajax form submissions. – Gazler Commented Nov 23, 2010 at 14:45
2 Answers
Reset to default 8The serialize()
method es from jQuery. Your statement is failing because form isn't wrapped in jQuery:
var form = $('#frm');
var data_string = form.serialize();
Or:
var form = document.getElementById('frm');
var data_string = $(form).serialize();
My guess is that you're referencing the "Traditional" DOM object using getElementByID and not using it through jQuery (which would traverse the form and add the information). Try using:
var data_string = $('#frm').serialize();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745382009a4625271.html
评论列表(0条)