Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting parameters to a url using the POST method without using a form

I want to post parameters to a URL using the POST method but I cannot use a form. Even if I do use a form, it would have to be auto-posted with out user interaction. Is this possible? How can I do this?

like image 639
Gaurav Sharma Avatar asked Aug 07 '09 11:08

Gaurav Sharma


People also ask

How do you send parameters to the post method?

In a GET request, the parameters are sent as part of the URL. In a POST request, the parameters are sent as a body of the request, after the headers. To do a POST with HttpURLConnection, you need to write the parameters to the connection after you have opened the connection.

How can I pass POST parameters in a URL?

You could use a button instead of an anchor and just style the button to look like a link. That way you could have your values in hidden fields inside the same form to be sent via POST. In addition to what Ben said, you can also let the link be a dummy and have it execute a javascript that submits a hidden form.

How can POST data without form in HTML?

An easy way to do a GET request without an HTML form is to use a query string: var url = "http://site.com/page?KEY=VALUE"; location.

How do I send a POST request using Javascript?

To send an HTTP POST request, we need to first create the object by calling new XMLHttpRequest() and then use the open() and send() methods of XMLHttpRequest. To receive notifications when the status of a request has changed, we need to subscribe to the onreadystatechange event.


2 Answers

Using jQuery.post

$.post(
  "http://theurl.com",
  { key1: "value1", key2: "value2" },
  function(data) {
    alert("Response: " + data);
  }
);
like image 158
Josh Stodola Avatar answered Sep 19 '22 13:09

Josh Stodola


You could use JavaScript and XMLHTTPRequest (AJAX) to perform a POST without using a form. Check this link out. Keep in mind that you will need JavaScript enabled in your browser though.

like image 34
Pablo Santa Cruz Avatar answered Sep 22 '22 13:09

Pablo Santa Cruz