To send request to and get response from the server using HTTP Get and HTTP post, we can use post()
and get()
methods respectively. In this way also browser post back doesn?t happen.
Post()
<input type="button" id="btnPost" value="Load Data using Post" />
<div id="divResult"></div>
<script>
$("#btnPost").click(function () {
$.post(
"jQueryAjaxData.aspx",
{ a: "20", b: "6" },
function (data) {
$("#divResult").html("<b>The result is: " + data + "</b>");
});
});
</script>
This is similar to .ajax method however this guarantees that ajax request will be sent to the server using html form post
method only. Here are the parameters to pass
var a = Request.Form["a"]; // a value will be 20 var b = Request.Form["b"]; // b value will be 6
Get()
<input type="button" id="btnGet" value="Load Data using Get" />
<div id="divResult"></div>
<script>
$("#btnGet").click(function () {
$.get(
"jQueryAjaxData.aspx",
{ ag: "2", bg: "6" },
function (data) {
$("#divResult").html("<b>The result is: " + data + "</b>");
});
});
</script>
This is similar to .ajax
method however this guarantees that ajax request will be sent to the server using html form get
method. The only difference between Post and Get is the method by which data is submitted to the page.
Here
var a = Request.QueryString["ag"]; // the value will be 2 var b = Request.QueryString["bg"]; // the value will be 6Views: 10017 | Post Order: 108