Posting data on server using asp.net - javascript

I have name and email id fields and want to post data to server to another website (if fields are valid) using form tags but i already have one form tag with runat="server", using second form tag causes second form to not show on page. I have JavaScript code to post data to server on form post. I saw something using action on button click, but how do i post data on button click
P.S I don't want to use iFrame, popup.

To send POST data on a form submit, try to use a submit button like this:
<input type="submit" value="POST_DATA" name="POST_PARAMETER_NAME">
Replace POST_DATA with your data you want to submit and replace POST_PARAMETER_NAME with the parameter name you want to access the data on the server.

If you already have a form on the page that uses asp.net web forms to communicate with the server then you would probably need to make an ajax request if you want to post back different data. This is quite easy these days using jQuery. The link bellow shows you how you may do this and how to create a web forms page that would accept your post. This way your current form and page would not need to change which is what it sounds like you are after.
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

Related

How can I transfer the information I get from the form to another page?

How can I show the information I got from the place where I entered the title and text on the announcement page?
repo:https://github.com/qswezy/spa1
We have added the form and we want to show it in the announcements
Forms usually have target page. So, this is the page that will receive your submitted data, usually in some type of POST array (if you submitted it as a post.) If this assumes JavaScript, you probably need to run an Express server to do this.

Post Array using window.location.href in ASP.NET MVC

I need to send data to a Controller to Post data currently I'm not using a form only I need to send an array for parameters, what is the right way to do it ?now I'm using this line of code but I know that it is used for Get method instead of Post method:
window.location.href = "#Url.Action("Edit", "PurchaseOrder")?arr"+urlParams;
the only easy way to post data to a controller is to do it through a form. but that doesnt mean the form needs any text input or stuff like that as long as code the data in and you make it invisible for a user you can just use a button that looks like a normal button but is actually a form in de code.
else if you dont want to use a form to send the data even if the inputs on the form are not visible you could use AJAX to send a post request but i dont think you want to do that.
if you are already getting the data from a different page in my oppinion it would be easier to just use sessions to store the values when you get them for the first time

Render entire HTML page from Flask using AJAX

My web app on the backend is Flask and I use Jinja2 and wtforms to dynamically generate content.
The main page that is generated is a table of all the sales for any given month. At the top of the table, there are select fields used to filter the sales, Month, Director, and Account Manager.
When someone selects an account manager, for example, from the Account Manager dropdown, I would like an event to be triggered that sends a "get" request back to the server with the selected account manager. The server would then generate the new filtered content and send the HTML page back to be rendered on the client.
I want the dynamic rendering to remain on the backend. I added an event listener to the Account Manager select field and then tried to use Axios to send an ajax call to the server using a "get" request, which works. I get the entire HTML document back as data.
My question is, how do I now render that entire HTML document returned to Axios? Or, is there a better way to do this?
I know I could easily create a form with those filter elements and then a submit button to send a "post" request back to the server and it will work. But, I really would like to send a "get" request when a select field changes without having the user click a button.
I was able to solve this on my own. I kind of answered it in my last paragraph of the question. A solution is to simply create a form that includes the filter select elements. I then added an event listener on each of the select elements. The function for the event listener then calls submit on the form. Pretty simple.

Is there a way to get the form data easily with JavaScript?

I was looking on how to get values of form data that are passed with POST requests and found this answer.
I know you you can get GET query parameters quite easily in JavaScript doing window.location.search but is there a way to do similar for POST request or document.forms is my only option?
To expand on what RUJordan said:
When you do a POST, the information is sent to the server using an entirely different method and does not show up in the URL or anywhere else that JavaScript can get access to it.
The server, and only the server, can see it.
Now, it is possible to take some of the form data and fill JavaScript variables and/or hidden form fields so the server can pass data back down to the client.
If you need more help, you'd be better off opening another question explaining exactly what problem you are trying to solve.
Do you want javascript to see the data was POSTed to load the current page?
JavaScript does not have access to the request body (where the POST content is) that loaded the page. If you want to be able to interact with the POSTed parameters, the server that received the request would need to respond with the necessary data written back out on the page where javascript can find it. This would be done after the form was submitted, as part of the response to that POST request.
Or do you want to know what your page could POST form the forms that are on it?
Inspecting document.forms will let you see what could be POSTed later if those forms were submitted. This would be done before the form was submitted, without a request being made.

Python - Fill and submit a HTML Form

I would like to fill in and submit a form on a web page using python. The form I want to interact with has several drop down boxes which are filled using JavaScript. I have looked at the mechanize library but it doesn't handle JavaScript. Can you suggest an alternate library/method for interacting with the form?
Cheers,
Pete
Selenium RC or Windmill (http://www.getwindmill.com/)
Examine the form's returned GET or POST values;
use urllib2 to submit synthesized requests directly.
The form effectively sends information back to the server (or maybe somewhere else) after you press the submit button.
I don't know how you would directly interact with the form, but you could just send the information back to the server in the same way as submitting the form would (without actually submitting it or physically pressing on things).
So for example some forms put the parameters specified in the form (and their values) at the end of the url in the HTTP request once submitting the form. Others put the parameters in the body of the HTTP request. In PHP i know that PHP automatically takes these parameters out for you (into a global array).
In this case you would simply put your own version of the parameters (names/values) in the HTTP request, by looking a what names/values there are in the forms source code.
Although the form may send its information to the server using javascript...
Sorry if that made no sense.

Categories

Resources