msg.d from asp.net webmethod is undefined

ViagraPharmaci

New Member
I'm trying to follow this article to get a value from a webmethod using jQuery AJAX. I've cut it down to a one-input form.Thing is, it always fails and msg.d is always undefined. In Firebug, I can see the POST and the data string is formatted correctly. I cannot, for the life of me figure out why this keeps failing. The breakpoint set in my webmethod gets hit but the page displays a failure message before it's fully run.Any ideas what's going on? Here's my code:Basic form:\[code\]<div id="contact"> <ul> <li><div>Name*</div> <input name="ctl00$ContentPlaceHolder1$txtName" type="text" id="ctl00_ContentPlaceHolder1_txtName" /> </li> </ul> <ul class="submit"> <li>* required</li> <li class="submit_button"> <input type="submit" name="ctl00$ContentPlaceHolder1$btnSubmit" value="http://stackoverflow.com/questions/14439664/Submit" id="ctl00_ContentPlaceHolder1_btnSubmit" /> </li> </ul> </div>\[/code\]jQuery:\[code\]<script type="text/javascript"> jQuery(document).ready(function () { $("#ctl00_ContentPlaceHolder1_btnSubmit").click(function () { var name = $("#ctl00_ContentPlaceHolder1_txtName"); $.ajax({ type: "POST", dataType: "json", contentType: "application/json", url: "Default.aspx/SendEmail", data: "{'name':'" + name.val() + "'}", success: function (msg) { alert("success"); alert(msg.d); }, error: function (msg) { alert("fail"); alert(msg.d); } }); }); });</script>\[/code\]WebMethod:\[code\][WebMethod]public static string SendEmail(string name){ return "success";}\[/code\]
 
Back
Top