Thursday, 19 January 2012

Calling Web Service Using Jquery Ajax



1. Create the Web Service To Send Email and Call that Web Service Using JQuery.

i. Create a form 















2. On the SubMit Button Write the Following Code on its OnClientClick="retun CallServiceMail()".

<script type="text/javascript">
        function CallServiceMail() {
            var name = $('#nameMsg').val();
            var email = $('#emailMsg').val();
            var phone = $('#phoneMsg').val();
            var messageemail = $('#messageMsg').val();
            var messageto = "info@abakinfotech.com";
            var subjectemail = "Enquiry from web site contact form";
            $.ajax({
                type: "POST",
                url: "SendEmail.asmx/SendMail",
                data: "{'nameemail': '" + name + "', 'emailid': '" + email + "', 'phone': '" + phone + "', 'message': '" + messageemail + "', 'emailTo': ' " + messageto + "', 'subjectemail': ' " + subjectemail + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                error: OnError
            });
            function OnSuccess(data, status) {
                if (data.d == "1") {
                    $('#nameMsg').attr("value", "");
                    $('#emailMsg').attr("value", "");
                    $('#phoneMsg').attr("value", "");
                    $('#messageMsg').attr("value", "");
                    $("#contactsubmit").show();
                    window.location = "thankyou.html#successMsg"
                }
            }
            function OnError(request, status, error) {
                if (request.statusText == 0) {
                    $("#contactsubmit").show();
                    alert("There is some error in sending mail, sorry for incovinience");
                }
            }
        }
    
</script>
</div>

our new blog site : http://blog.hintechnology.com

No comments:

Post a Comment