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
Related
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
So I'm trying to make a website where you put in a username and it will give you data about that username using an API. Right now I have it set up so you have to type the username in every time you're on the website, but I was wondering if it's possible to put the username in the link and still be able to retrieve it to put it into an API and use the API's response in the website?
For example, would it be possible to have something like http://website.com/?username=XXXXXXXXXand to be able to get the part after ?username= and to save it to a string or something to put into the API using JavaScript or jQuery? Any help would be appreciated :)
why don't you saving username in cookie/storage/session after user input?your ways is complex and unreliable.or may be you could use the rest url format like this: http://{username}.example.com/api or http://www.example.com/{user}/api then your backend always retrieves username from this path and you needn't add parameters manually.
I'm looking to capture and save the state of a page (Django template + backend) after the user makes some modifications (through JQuery) to the appearance of the page. Now that I've gotten hold of the innerHTML using a JS variable, I need to send it over to the Django view that will do the saving. How do I call this Django view and pass it the JS variable?
P.S: First ever question on stackoverflow, please let me know if the question isn't clear or is improperly formatted.
Handiest way to get started is to first make a proper form and a django view that reacts to it ("request.post"). The form should have fields for whatever you're changing in the page.
Next up, submit that form's variables from your page with jquery.ajax.
So the idea is to isolate the various problems:
What should be the form parameters?
Get a view running that makes the actual changes.
Get the javascript working.
Effort
I've read this question, but I still think there has to be a way to do this client side.
Case
I'm submitting a form that has a few inputs. When the form is submitted, the primary key of those inputs is shown on a results page along w/ other data and a different form.
The effect I'm trying to do is if the input-pk is modified, I want it to reload the page (think window.location.reload()), only I want to update that PK parameter's value with the changed value.
window.location.reload takes one of two values (true/false), which distinguishes if it should use browser cache or not. Thus, it seems like it should be accessible, especially since the Firebug::Net plugin shows the param in the HTTP Header.
The form requires 'Post' submissions, which adds a little more complexity.
Alternative
The other thing I've considered is to store the values in a cookie right before submission, which I can retrieve on the next page and then submit another Post; however I'd like to refrain from exposing the data in Cookies.
AFAIK, Javascript does not have access to the POST body. Can't think of an API call for that! If you are using php/.net/ruby, you can encode the POST body as JSON that your JS can use when it's reloaded, can't you?
I have a site that request that they could send out different urls to clients to track what links are being used. I told them to use google analytics but they are requesting to stay away from it.
What they are asking is they want to send a url to there customers such as,
http://www.yoursite.com/?link=Nameoflink
They want to get that cookie and set it.
Then when the contact form is used they want to be able to submit that link name with the form submission to show what links are being used to go directly to there site.
I was told this is possible but i have no knowledge of that custom of javascript or cookie expertise... =/
You can get the value of the params passed in through the url with location.search. To get the value of the param, use the location.search and then find the specific url value, then set that in another hidden text field or something...
if (location.search){
var search = location.search.substr(1).split("&"),
url = search.split("=")[1];
document.getElementById('hiddenInput').value = url;
}
Note- the code above assumes that your search string only contains the URL value & that the URL is first. If not, it is likely this will fail. You can update the code to account for that by checking to make sure that search.split("=")[0]==="url" or expanding it to parse out all of the search params into an object that you can reference by key.
Yeah, google analytics would make this a lot easier, especially if you had a specific page that would serve as a drop-point, telling you how many people click this special link.
Without google analytics, you could get the GET variable values via a PHP or ASP page script and have them set that way, or you can use soley JavaScript to take care of cookie setting and retrieval.
For JavaScript, these links should point you in the right direction:
JavaScript cookies:
(I can only post one link, but check out W3C School's article on JavaScript cookie handling)
Extract GET values via JavaScript:
http://www.go4expert.com/forums/showthread.php?t=2163