admin管理员组文章数量:1426810
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();
本文标签: phpRewrite of this code because serialize() doesn39t workStack Overflow
版权声明:本文标题:php - Rewrite of this code because serialize() doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745382008a2656207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论