how to call server side method from jquery

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jul 2008
Posts: 66
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

how to call server side method from jquery

 
0
  #1
Oct 20th, 2009
Hi All,

I'm new to this jquery and i found some article, implemented but its server side method is not firing. Plz if you know help out this probelm.

These is the code implemented in my application in jquery side.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript" ></script>
  2. <script language="javascript">
  3. $(document).ready(function() {
  4.  
  5. $("#btnClick").click(function() {
  6. var email = $("#txtemail").val();
  7. $.ajax({
  8. type: "POST",
  9. url: "TestingEmail.aspx/DNSValidation",
  10. data: "{EmailAddress:" + email.toString() + "}",
  11.  
  12. success: function(response) {
  13. alert(response.d);
  14. // if (response.bolDNSFlag != "true") {
  15. // alert("Plz try again");
  16. // $("#txtemail").focus();
  17. // }
  18. },
  19. error: function() {
  20. alert("Error");
  21. }
  22. });
  23. //Call the PageMethods
  24. $.ajax(options);
  25.  
  26. });
  27.  
  28.  
  29. });
  30. </script>

and server side is
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. [WebMethod]
  2. public static string DNSValidation(string EmailAddress)
  3. {
  4. Boolean bolDNSFlag = false;
  5. try
  6. {
  7. if (isEmail(EmailAddress.Trim()))
  8. {
  9. string[] host = (EmailAddress.Trim().Split('@'));
  10. string hostname = host[1];
  11.  
  12. IPHostEntry IPhst = Dns.GetHostEntry(hostname);
  13. IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
  14. Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
  15. s.Connect(endPt);
  16. bolDNSFlag = true;
  17. }
  18. }
  19. catch (Exception exp)
  20. {
  21. bolDNSFlag = false;
  22. }
  23. return bolDNSFlag.ToString();
  24. }

Im not geting the breakpoint. Plz let me know if u have any idea.
signOut
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 102
Reputation: jomanlk is an unknown quantity at this point 
Solved Threads: 18
jomanlk jomanlk is offline Offline
Junior Poster
 
0
  #2
Oct 20th, 2009
Fist (in FireFox) press CTRL + SHIFT + J and load the Error console. Clear the contents before you reload the page. When you reload the page, if errors appear, fix them.

Is the call jquery ajax call being made? If you're using firefox, install the firebug extension. This extension will allow you to look at the ajax calls that are being made. It will make it easier for you to debug.

Also, jQuery offers a much simpler construct for ajax.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. jQuery.post(
  2. "TestingEmail.aspx/DNSValidation",
  3. {"EmailAddress": email.toString()},
  4. function(data){
  5. alert(data);
  6. });

Also, I think you may be quoting the wrong parts in the data variable. Not sure on that, the error console will help you out there.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC