Jquery Ajax Contactus Form

Harika Polavaram asked on June 26, 2014 10:54

Hi,

I have a Jquery form in Kentico and I would like to post that to a IIS sever which has a method written in c# dot net to get the form fields and send out an email.I tested it locally in IIS server and the form is working.Now, I tried to move my Jquery to Kentico where the users will submit the form.For some reason, it is not able to post to IIS server.Can you please help me on this.

Jquery Code:

Recent Answers


Harika Polavaram answered on June 26, 2014 10:58 (last edited on June 27, 2014 02:45)

<body>
    <div id="form2" class="form2">
        <span>Email:</span><input id="email" type="text" />
        <input id="btn" type="button" value="button" />
    </div>

    <script type="text/javascript">
       $(function () {
           alert("Hello");
           $("#btn").click(function () {
               alert("Click on Button");

               $.ajax({
                   url: 'https://kenticoformdev.ent.lolcentral.com/KenticoForm.aspx/PostForm',
                   data: "{email: '" + $("#email").val() + " '}",
                   type: 'POST',
                   dataType: 'jsonp',
                   contentType: "application/json; charset=utf-8",
                   success: function (data) {
                       //                       alert(data.d);
                   }

               });

           });
       });
    </script>

</body>
0 votesVote for this answer Mark as a Correct answer

Bill Tran answered on June 27, 2014 09:24

Did you follow the ASP.NET Standard for creating a web method.

signature must be public static string MethodName(your parameters)

You also need to decorate it with the [WebMethod], [ScriptMethod] attributes.

If it doesn't follow ASP.NET standard, your jquery ajax post cannot find the method and therefore you'll receive a 404.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on June 30, 2014 12:13

Can you post the error you are getting? As Bill rightly said you need to take care of the mentioned things. I did something this recently. I may help you out.

0 votesVote for this answer Mark as a Correct answer

Harika Polavaram answered on July 2, 2014 17:27

Thank you very much Bill and Chetan.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.