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

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

programmeradmin1浏览0评论

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!");
      });
发布评论

评论列表(0)

  1. 暂无评论