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
Related
I have a page which is coded like this. http://localhost/test/index.html?Job=123456&Customer=11111&Number=32333
What i want to do is read this form data when the page is input, as i need to add Job and Customer to the html form i have which is using method="post" and using action="phppage.php" to post this data along with an array to phppage.php, which is then using $_GET["Job"]. I have tried various javascript functions from these pages, but just seem to be missing the values. I have confirmed the data will post by using <input type="hidden" value="12345" name="Customer" id="customer"> hard coded and this is being brought through. What i need to do is set value for both required fields. Appreciate any help with the javascript function i need.
First of all, it is not secure to pass value in url like this, if you are using javascript, you have to use encodeURIComponent to encode your url.
and second, you can get the passed parameters from url using these codes:
var decodedUrl = decodeURIComponent(window.location);
var Parameters = decodedUrl.split("&");
First thing the link you have added here wont work since its in your local machine(which means it will be accessible only in your pc).
Second if your form is using post method for sending data to the page you cant get it with $_GET['somename']. you should use $_POST['somename']
since i cant see your code i would
create the form reading this tutorial http://www.w3schools.com/html/html_forms.asp
then create the php reading this https://www.tutorialspoint.com/php/php_get_post.htm
also note that your url shows that your page is using get method to send data to the page
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.
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/
I read online about how to send a variable from javascript with ajax but I am not sure that solution fit my needs.
What I am trying to do is this:
I have an automated form for creating a row at my DB.
What I Want to do is run a javascript code that will create a variable with logic based on the user input and than send this variable along with all the other fields that are automatically being sent because of the automated creation and binding of the model.
Basically what I want is to add another array to the automated post call that I didn't wrote because it is being generated automatically by mvc. and than I can retrieve this variable (array at my case) at the create method on the controller
Do you have a solution for this?
Thank you very much
You could add some hidden fields to the form and use Javascript to fill their values in the submit event.
I want to make the results of an ASP.NET form POST "bookmarkable", and I'm thinking of using query parameters to accomplish this.
The idea is that a user will visit http://domath.com and they will type in a math problem, and view the results. The query and results are visible at http://domath.com?ProblemID={some guid here}
The only part I don't really know is how do I change the target of the form URL since I'm using a POST instead of a GET..
Here are the options I came up with, and I'm not sure what is practical
Submit form as usual, server redirects to a URL with the new parameters attached
Use a webservice or callback to get new URL. Javascript then updates form target
The first option is the easiest and most common. It follows the Post/Redirect/Get model, which avoids double form submission in addition to letting you bookmark the resulting page.