954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to call server side method from jquery

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.

<script type="text/javascript" ></script> 
        <script language="javascript">
            $(document).ready(function() {

                $("#btnClick").click(function() {
                    var email = $("#txtemail").val();
                    $.ajax({
                        type: "POST",
                        url: "TestingEmail.aspx/DNSValidation",
                        data: "{EmailAddress:" + email.toString() + "}",

                        success: function(response) {
                        alert(response.d);
//                            if (response.bolDNSFlag != "true") {
//                                alert("Plz try again");
//                                $("#txtemail").focus();
//                            }
                        },
                        error: function() {
                            alert("Error");
                        }
                    });
                    //Call the PageMethods
                    $.ajax(options);

                });


            });
        </script>


and server side is

[WebMethod]
    public static string DNSValidation(string EmailAddress)
    {
        Boolean bolDNSFlag = false;
        try
        {
            if (isEmail(EmailAddress.Trim()))
            {
                string[] host = (EmailAddress.Trim().Split('@'));
                string hostname = host[1];

                IPHostEntry IPhst = Dns.GetHostEntry(hostname);
                IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
                Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                s.Connect(endPt);
                bolDNSFlag = true;
            }
        }
        catch (Exception exp)
        {
            bolDNSFlag = false;
        }
        return bolDNSFlag.ToString();
    }


Im not geting the breakpoint. Plz let me know if u have any idea.

Renukavani
Junior Poster
123 posts since Jul 2008
Reputation Points: 10
Solved Threads: 23
 

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.

jQuery.post( 
	"TestingEmail.aspx/DNSValidation", 
	{"EmailAddress": email.toString()},
	function(data){
		alert(data);
	});


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.

jomanlk
Junior Poster
106 posts since Oct 2009
Reputation Points: 13
Solved Threads: 19
 

Change line 10 to:

data: "{EmailAddress: " + "'" + email + "'" +  " }",

/* Weird JavaScript :)

BTW: All of these shall work:

 data: '{"testData":"testing"}',
 data: "{testData: " + $('#<%= ddlCtrl.ClientID %>').val() + " }",
 data: "{testData: " + "'" + inputData.val() + "'" + " }",

~ Boris Momtchev
*/
Boris.Momtchev
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 1
 

Thanks for all your reply

Renukavani
Junior Poster
123 posts since Jul 2008
Reputation Points: 10
Solved Threads: 23
 
Thanks for all your reply


So, just glancing at your sig, I wonder if you feel this thread is solved?

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You