944,189 Members | Top Members by Rank

Ad:
Oct 20th, 2009
0

how to call server side method from jquery

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Oct 20th, 2009
0
Re: how to call server side method from jquery
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.
Reputation Points: 13
Solved Threads: 19
Junior Poster
jomanlk is offline Offline
103 posts
since Oct 2009
Mar 25th, 2010
-1
Re: how to call server side method from jquery
Change line 10 to:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. data: "{EmailAddress: " + "'" + email + "'" + " }",
  2.  
  3. /* Weird JavaScript :)
  4.  
  5. BTW: All of these shall work:
  6.  
  7.  data: '{"testData":"testing"}',
  8.  data: "{testData: " + $('#<%= ddlCtrl.ClientID %>').val() + " }",
  9.  data: "{testData: " + "'" + inputData.val() + "'" + " }",
  10.  
  11. ~ Boris Momtchev
  12. */
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Boris.Momtchev is offline Offline
1 posts
since Mar 2010
Mar 26th, 2010
0
Re: how to call server side method from jquery
Thanks for all your reply
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Mar 26th, 2010
0
Re: how to call server side method from jquery
Click to Expand / Collapse  Quote originally posted by Renukavani ...
Thanks for all your reply
So, just glancing at your sig, I wonder if you feel this thread is solved?
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: get server ip address.
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: AJAX loading animation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC