最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Easiest way to alert a form's data - Stack Overflow

programmeradmin0浏览0评论

Simple question I can't seem to get right. I have a form #formOne, I need to alert it's data. Something isn't working,

$("#formOne").submit(function(){
  alert("you are submitting" + data);
)};

If not data what do you use after +?

Thanks!

Simple question I can't seem to get right. I have a form #formOne, I need to alert it's data. Something isn't working,

$("#formOne").submit(function(){
  alert("you are submitting" + data);
)};

If not data what do you use after +?

Thanks!

Share Improve this question edited Aug 14, 2018 at 16:14 informatik01 16.4k11 gold badges78 silver badges108 bronze badges asked Oct 5, 2010 at 2:37 Dirty Bird DesignDirty Bird Design 5,55313 gold badges67 silver badges127 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You can use .serialize() to see what the POST string looks like:

$("#formOne").submit(function(){
  alert("you are submitting" + $(this).serialize());
});

Make sure that #formOne is the form itself, so that this refers to the <form> element when serializing. For debugging you may always want to try this instead (using Firebug or Chrome):

$("#formOne").submit(function(){
  console.log($(this).serializeArray());
});

This will print out as an array of objects with a name and a value property, a bit easier to read, at least to me.

发布评论

评论列表(0)

  1. 暂无评论