$.ajax post method is giving null in the server side

Posted by Sheonarayan under Error and Solution on 5/28/2014 | Points: 10 | Views : 413 | Status : [Administrator] | Replies : 3

Problem


When you try to post data to the server using jQuery.Ajax function with type as "POST", you are not able to retrieve form data.

$("#bntAjax").click(function () {
$.ajax({
url: "jQueryAjaxData.aspx",
type: "POST",
dataType: "html",
async: false,
data: {
"ag": "randel"
},
success: function (obj) {
$("#divResult").text(obj);
}
});
});


In the above code, when you try to retrieve Request.Form["ag"], you get null when you post data from INTERNET EXPLORER (IE) browser.

Solution


The solution is not to use IE but Google Chrome or FireFox as IE doesn't support form post method in javascript.

This is strange but true, alternatively you can create a WebMethod and you will be able to get these data to the server but for that you will have to use json.

Regards,
Sheo Narayan
http://www.dotnetfunda.com



Responses

Posted by: Vuyiswamb on: 7/6/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Sheo all your Error and Solution Post must fall under Error and Solutions. Please Update

Thank you for posting at Dotnetfunda
[Administrator]

Sheonarayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 7/7/2014 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Dear Vuyiswamb,

Thanks. The category named "Error and Resolution" has been updated to "Error and Solution".

Regards

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sheonarayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/7/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Thank you Sheo

Thank you for posting at Dotnetfunda
[Administrator]

Sheonarayan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response