I've got some Javascript which gets the HTML for a form from the server via an XMLHttpRequest, and displays the form on the page.
What I'd like to be able to do is extract the data which would be sent via POST if the form was submitted, then send it via another XHR. The tricky bit is that the form could contain different elements of different types.
Is there a way of doing this without having to inspect each element on the form, determine its type, manually extract the data based on the type, and build it all into a query string?
Is there a way of doing this without having to inspect each element on the form, determine its type, manually extract the data based on the type, and build it all into a query string?
No, there isn't, but there are prewritten libraries that have the code for that already written. e.g. jQuery serialize
Note that if you want to make a POST request, then the data should go in the request body, not the query string.
Related
I have a simple form with a button (submit), two textbox fields and two hidden fields. On submit, I would like to pass in 3 parameters to a service using a WSDL URL. More specifically, I would like to pass in the ENTIRE form (including data entered in form) as a string (in xdp or pdf format) as one parameter and the values of the two hidden fields as two other separate parameters.
I am using Javascript to call the web service and pass in the parameters.
I have been struggling with trying to pass in the ENTIRE form as an xdp or pdf as a string parameter to call the web service. Is this even possible?
Thank you!
Yes. You can set that up inside the submit button settings, either sending form data as plain xml or xdp.
Well I couldn't figure out how to get the entire xdp. HOWEVER...
As it turns out I found out how to get the entire pdf.
You MUST get the base64 encoding in order to get the entire pdf. For some reason if you do not encode the Collab.documentToStream into base64 it doesn't return the entire pdf (only a small section of it). This is my solution:
var documentString = util.stringFromStream(SOAP.streamEncode(Collab.documentToStream(event.target), "base64"));
From that you can decode the string from base64 to ansi on the server side which should give you the entire pdf to be stored or opened.
I will accept this as an answer to my own question. I edited my original question for clarification.
It is bad practice to pass this in the URL. If you want to use a String, it should be passed in the body of the request (i.e. a REST endpoint that accepts a string input). Passing this in the URL could eventually reach the URL length limit if the form or data is long enough.
So, I know that when I submit a form whose method is POST that the server receives the contents of that form and then processes them accordingly, and then returns a page with the desired content. What I am trying to learn is what exact query url is being passed to the server side script when I submit a form on a website that does not belong to me. The reason I want this query string is so that I can make use of the server side script programatically with my own data. There is no public API served by this website, but I would like to formulate my own.
So my question is, is there a way to intercept the POST as a query string URL? Perhaps by using a javascript console in browser?
I know I can look at the source code for the page and find the names/values of the form fields. However, there also happens to be a hidden field on this page whose properties are set by javascript during validation at submission time. How should I go about this?
You can use an extension for intercept the data : Tamper Data on FireFox
https://addons.mozilla.org/fr/firefox/addon/tamper-data/
You can intercept and modify all headers requests
I am trying to implement GSA(Google Search Appliance) in my app. I want to use the REST(JSON) call that the GSA provides. The point for this question is that, the GSA needs a POST request in order to return the JSON response.
Now when I made a new dummy HTML page with a form and make a POST request with parameters I get a successful response(JSON)
But, when I try using the $.post(...) method to send a POST request to the URL I am not getting the actual response, but some error page.
I just wanted to know is there a difference between a standard submit and an ajax form submit. If yes, is there any workaround for this situation.
Please Help. Thanks in Advance.
If you want to submit the form through ajax but in the conventional way, You should have a look at jquery form plugin . Just make your submit button to type button and on click submit your form thorugh .ajaxSubmit(). I think this will solve your problem.
GSA search protocol is based on HTTP GET. All search parameters need to be passed in via query string. Also, out of box, GSA only returns either HTML or XML results. You could apply an xslt that transforms xml to JSON -- but I'm yet to find one that works really well (i.e., I've found a couple but they don't return valid JSON in all instances).
I know that I can submit form information from a web page by using the #MultipartForm annotation to bind a POJO to a form. (See How do I do a multipart/form file upload with jax-rs?).
What I would like to do, however, is make a Restful call that returns a POJO containing values, and have those values fill in the appropriate form values, which can then be edited and submitted by the user. I know I'd probably need to use JavaScript to first make the rest call, but at that point, is there a way I can use the result to fill in the form?
I could have my rest call return JSON representing the form and use those values to fill in the form with JavaScript, but it would be cool if this could happen automatically, similar to form posting.
Thanks!
I would like to send raw post data using straightforward DHTML, but without using the XMLHttpRequest object. Is this possible to do this, for example, by forcing an HTML form element's post data to an arbitrary string?
Before you post the form, you could dynamically add html input elements (with values) to the form, and then call form.sumbit(). This will still refresh the page though.
The only way that I'm aware of to post data without refreshing the page is using the XMLHttpRequest object. Using jQuery makes this whole operation pretty trivial http://api.jquery.com/jQuery.post/ , so I'm not sure why you don't want to use ajax to accomplish this?
You can easily generate a string that resembles a POST request. There is not much difference between a POST and a GET. Using GET, the parameters are added behind the url. When POSTing, the parameters are added in the same way, but below the headers.
See developers.sun.com for an example.