javascript - Is there a way to submit a "fake" form using jQuery? - Stack Overflow

What I want to do is make a POST request with arbitrary params, much like submitting a form. That is no

What I want to do is make a POST request with arbitrary params, much like submitting a form. That is not merely doing the XHR. What I ideally want is to emulate a submit (like submiting a form, not POSTiing and then redirecting). I want to avoid the latency of $.post + window.top.location = blah

The most direct way would be to have a 'fake' form and insert a bunch of elements, then serialize and use jQuery.submit(), something like Is there a way using jQuery to submit a form without the elaborate field by field breakdown?

I wish there were a more elegant way.

My use case is that I am gathering a bunch of random fields through external API calls (from Facebook and other services) and want to submit ALL that info at once to user creation, as if the user filled out all this information and pressed 'submit'

Any suggestions? Thanks!

What I want to do is make a POST request with arbitrary params, much like submitting a form. That is not merely doing the XHR. What I ideally want is to emulate a submit (like submiting a form, not POSTiing and then redirecting). I want to avoid the latency of $.post + window.top.location = blah

The most direct way would be to have a 'fake' form and insert a bunch of elements, then serialize and use jQuery.submit(), something like Is there a way using jQuery to submit a form without the elaborate field by field breakdown?

I wish there were a more elegant way.

My use case is that I am gathering a bunch of random fields through external API calls (from Facebook and other services) and want to submit ALL that info at once to user creation, as if the user filled out all this information and pressed 'submit'

Any suggestions? Thanks!

Share Improve this question edited May 23, 2017 at 12:04 CommunityBot 11 silver badge asked Nov 25, 2011 at 7:56 ambertchambertch 7,6495 gold badges31 silver badges42 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

yes

you can use $.ajax (example)

or $.post and $.get ... example:

$.post(
          "url_to_page",
          /* string like this: "text=me%20man&[email protected] or an object": */
          {text: "me man", mail: "[email protected]"}
      )
      /* you can check if the request was submitted successfully */
      .success(function(data) {
          alert("Success!");
          alert(data); //data on page
      })
      /* you can check if the request failed */
      .error(function() {
          alert("Error!");
      });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745281984a4620330.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信