开发者

post method in javascript

How i can pass the value from javascript post method from one page (home.aspx) to another page(post.aspx) which needs to open in new window using window.open method .? My code below:this javascript function called in button click event.

function postwith () {
  var myForm = document.createElement("form");
  myForm.method="post" ;
  myForm.action = post.aspx ;
    var myInput = document.createElement("input") ;
    myInput.setAttribute("name", 'user');

    myForm.appendChild(my开发者_C百科Input) ;

  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;
}


<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="postwith();"/>

I want access the value (user) in page load event of post.aspx pge and this page should open in new window.


You need to make sure you are sending a complete post request with HTML and BODY tags. See this SO question on JavaScript POST. I don't see you opening a new window so see the aforementioned post on how to do that also.


You can pass your values by post, just declaring a form in your html, and then in javascript making something like:

document.form.name_of_the_form.submit();

Of course, the action of that form must be the new page you want to open. You also must pass your values inside fields (normally type="hidden") from the form.

Instead, you can also pass your desired values by GET method, through the url, with window.open in javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜