Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hiiiii ,
i hope anyone tell me what's wrong on below code , and why it is not working .

webmethod in aspx.cs page .
C#
[webmethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
 public static List<Problem> GetProblems()
 {
     List<Problem> allproblems = new List<Problem>();
     using (TMEntities tm = new TMEntities())
     {
         allproblems = tm.Problems.ToList();
     }
    return allproblems;
 }


and below is HTML

HTML
<script type="text/javascript">
       $(document).ready(function () {
              $.ajax({
                   type:"POST",
                   url: "WebForm1.aspx/GetProblems",
                   data: "{}",
                   datatype: "json",
                   contentType: "application/json; charset=utf-8",
                   success: function (data) {
                       alert('success');
                   },
                   failure: function (response) {
                       alert("fail");
                   }
               });
           });
   </script>



when i run the application nothing happened and when i press ctrl+shift+j to see the errors in browser , below error appeared


Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Posted
Comments
Anthony Mushrow 20-Sep-14 18:08pm    
If you're getting an Internal Server Error then it's likely an exception is being thrown on the server. If your using Visual Studio you can run the website with the debugger attached, you can either set a breakpoint and step through to make sure everything is all right, or if you're getting a First Chance Exception when calling your GetProblems API you can halt the execution of the program by enabling the exception by going to Debug->Exceptions.

JavaScript
url: "WebForm1.aspx/GetProblems",


I think this is the problem..Why this URL is like this..Use the ClassName/GetProblems
Or Use the full path

Using firebug network tab, Check the function is calling or not
 
Share this answer
 
Comments
Hercal 20-Sep-14 12:46pm    
i have another function and i run it with the same url , pagename/method name , it was worked fine . , any idea ??
500 Internal Server Error means, it is hitting your server and that is returning the error. My suggestion would be to check the method GetProblems by debugging each step. I guess the return is the problem. Once you debug you will surely resolve that.
Thank you. . :)
 
Share this answer
 
Comments
Hercal 21-Sep-14 13:02pm    
i can't debug it , it is a webservice and it is run once the document.ready is run

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900