October 10, 2012

AJAX Internal server error

Question by user751828

I couldnt find out what is the error.

 <script type="text/javascript">
         $(document).ready(function () {
             $("#btnsumbit").click(function (e) {
                 e.preventDefault();
                 $.ajax({
                     type: 'POST',
                     data: '{"username":"' + $("input#txtuser").val() + '","password":"' + $("input#txtpwd").val() + '"}',
                     url: 'http://localhost:53179/hdfcmobile/WebService.asmx/Login_Data',
                     contentType: 'application/json; charset=utf-8',
                     dataType: 'json',

                     success:
                  function (data, textStatus, XMLHttpRequest) {

                      var status = data.Status;
                      alert(data.d);




                  },
                     error:
                  function (XMLHttpRequest, textStatus, errorThrown) {
                      alert(textStatus);
                  }

                 });

             });
         });


    </script>

I am getting 500 internal server error.How to call this webservice.I have passes the method with the url.Thanks for any help…

Answer by Starx

First thing, the way you are sending is wrong, send it like this

data:  {

    "username": $("input#txtuser").val(),
    "password": $("input#txtpwd").val()

}

Next make sure, url: http://localhost:53179/hdfcmobile/WebService.asmx/Login_Data is returning JSON output.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!