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.
Related
Sometimes when making an HTTP request to download a file (e.g. PDF, XLSX, etc.) from the own webserver, it is necessary to use the HTTP method POST, because it requires dynamic input data. I have been trying different ways to reduce that to one single HTTP request for best performance, but could not succeed.
As JavaScript with the XMLHttpRequest object (AJAX) can not "download" files, I guess it requires an HTML workaround. The only working solution I found for that case is generating a form element wrapping input elements containing the data. I could not find a way how to send boolean values via this, as AJAX is able to. That would mean: it is not suitable for a standardizable implementation.
My question is: How can I download a file via one POST request which can include boolean values (JavaScript)?
In case it is important: The backend system I use is Ruby on Rails
As #Pointy mentioned, boolean values are always translated to strings in HTTP communication. I was wrong about that in my question. That means, converting a JavaScript JSON string or a classic object to an HTML form (then submitting and deleting it) works!
Actually sending an AJAX request and then manually triggering a link click to the generated file has the advantage of being able to use a progressbar.
I'm using a web server framework which works with only GET requests, at the moment I'm trying to pass a large amount of data, that is the text content in a textarea which comes from user input, into another page which echoes the user's input.
I've attempted Querystrings but I end up receiving the error "Requested URL too long".
Any suggestions as to what method I should use?
If you can only send data encoded in GET requests, then you will have to break up the request and send it in multiple parts.
You could either use Ajax or store the entire set of data in localStorage and fetch each chunk in turn as the page reloads.
One approach would be to make a request to an end point that allocates you a unique ID. Then send a series of requests in the form: ?id=XXX&page=1&data=... before closing it with ?id=XXX&total_pages=27 at which point you assemble the different pieces on the server.
This way lies madness. It would be much better to add POST support to your framework.
Try using Javascript Cookies.
you can store the textarea value there and then read it in another page (or wherever you want).
Here's a tutorial
http://www.w3schools.com/js/js_cookies.asp
I'm trying to implement a third party tool. This tool uses a form with the post method to send data to their site. Is there any way that I can mimic this action without using the form tag? I don't know much about jquery post and same domain (this is sending it off to a different domain) so I don't know if there would be an issue with this.
Everything that I've found in my search talks about ajax and returning content after you post but all I want to do is to take the customer to the third party's site after they have submitted the form.
thanks!
You cannot send data to a different domain with AJAX. Its not permitted by the browser. As for can you do it without a form element, yes. Just encode the data as it would look in a browser get URL like http://site.com/search?query=I+love+js&perpage=10&page=2
datatosend="field1="+value+"&field2="+value2
$.post(url,datatosend,function(data){//do something with data. location.href="new location"}
Yes you can.
Check out this post.
https://stackoverflow.com/a/1078991
also found in the docs
http://api.jquery.com/jQuery.post/
http://api.jquery.com/jQuery.post/
and then you can do a location.replace() when it is completed
function replaceDoc()
{
window.location.replace("http://www.thatsite.com")
}
I need to submit some information to my servlet. Once I submit this information, I'll receive a PDF from the servlet based on the data. I know I can construct the URL and pass parameters to it using HTTP GET. Suppose my form data is too large.So is it possible to do this using a hidden iFrame? I'll submit the parameters using the hidden iFrame and in my servlet, I write the PDF to the response stream. Will this work? If it works can someone please suggest me how to do this?
You'll need to set the target to the iframe you want to submit it to.
<form action='...' name='theform' target='theiframe'>
.
.
.
<iframe name='theiframe' src='...'>
</iframe>
</form>
This forum post has some details : http://forums.powweb.com/showthread.php?t=77213
Hm, which way do you want to sent the data using your iframe? I think you're limited to either GET or POST there, too. Means, if your data is too large, the iframe won't help sending your data.
What server backend do you use? You might be able to configure the maximum size of request data (post / get).
Please have a look at this message for more information about this.
In my eyes, using the hidden Iframe method is very old school, almost like before the great days of Ajax methods.
You can use jquery Ajax call and serialize your full form passing all variables. Remember to check your request size in your config, in case it post reaches maximum size.
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).