asp.net - AJAX - "Success" action is not invoked when specifying contentType and dataType -
i run little bit of problem executing `ajax request.
when specifying contenttype , datatype, success section not executing. however, when omitting that, executing, showing entire content of generated html page.
here ajax call:
$.ajax({ type: "post", url: "default.aspx/generatepdfs", data: '{frequency: "' + $('#ddlfrequency option:selected').text() + '" }', contenttype: "application/json; charset=utf-8", datatype: "json", success: function (data) { $('#rptdisplay').text(data); alert("1"); }, failure: function () { // $('#rptdisplay').text("error"); alert("2"); } }); this code behind:
[system.web.services.webmethod] public static void generatepdfs(string frequency) { string test = frequency; httpresponse response = httpcontext.current.response; response.write(test); } this fragment of html page:
<div id="rptdisplay" class="well" runat="server" clientidmode="static"> </div> i need display data returned web method in div section.
what doing wrong?
hope you:
contenttype :when sending data server.
datatype: type of data you're expecting server. if none specified, jquery try infer based on mime type of response .
please find code:
[system.web.services.webmethod] public static string generatepdfs(string frequency) { string test = "frequency";//hard code value httpresponse response = httpcontext.current.response; return test; } design: <asp:content runat="server" id="bodycontent" contentplaceholderid="maincontent"> <div id="rptdisplay" class="well" runat="server" clientidmode="static"> </div> <script src="scripts/jquery-1.7.1.min.js"></script> <script src="scripts/jquery-ui-1.8.20.min.js"></script> <script type="text/javascript"> $.ajax({ type: "post", url: "default.aspx/generatepdfs", data: '{frequency: "' + $('#ddlfrequency option:selected').text() + '" }', contenttype: "application/json;charset=utf-8", // datatype: "text/json", success: function (data) { debugger; if (data.d!="") { $('#rptdisplay').text(data.d); } alert("1"); }, failure: function () { // $('#rptdisplay').text("error"); alert("2"); } }); </script>
Comments
Post a Comment