0

I have Web method in Asp witch I use to load events to Full calendar. Its work fine from code(in local) and on server IIS ver. 10. But when I open App from browser events not loaded and I got message in (Inspect mode) POST Internal Server Error 500. I try to call asmx page from browser and Its working but I dont have option to Invoke like on server.

I check folder privelleges on server and thats looks fine

    $(document).ready(function () {
    var events = [];
    var ostalo = [];
    var userrola ="<%=Session["Rola"].ToString()%>";
    var userid ="<%=Session["userId"].ToString()%>";
    $.ajax({
        type: "POST",
        url: 'taskovi.asmx/UzmiTaskove',


        dataType: "json",
        success: function (result) {

            if (userrola== "Administrator") {
                $.each(result, function (i, data) {
                    events.push(
                        {
                            ID: data.ID,
                            title: data.title,
                            start: data.Start,
                            end: data.End,
                            backgroundColor: "rgba(51, 121, 183, 1)",
                            borderColor: "orange",
                            textColor: "white",
                            allDay: true

                        });
                });
            } ..etc...

          AND WEB METHOD

         [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public void UzmiTaskove()
    {
        List<events> listaTaskova = new List<events>();
        string CS = Properties.Settings.Default.conn.ToString();
        using (SqlConnection con = new SqlConnection(CS))
        {
            SqlCommand cmd = new SqlCommand("UzmiTaskoveSve", con);
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            SqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                events tas = new events();
                tas.ID = rdr["ID"].ToString();
                // tas.IdProjekta = Convert.ToInt32(rdr["IdProjekta"]);
                tas.title = rdr["Opis"].ToString();
                tas.Start = rdr["DatumPocetka"].ToString();
                tas.End = rdr["DatumZavrsetka"].ToString();
                tas.IdZap = Int32.Parse(rdr["IdZap"].ToString());
                //tas.Status = rdr["Status"].ToString();
                //tas.BrojSati = rdr["BrojSati"].ToString();
                //tas.Dokumenta = rdr["Dokumenta"].ToString();
                listaTaskova.Add(tas);
            }
        }
        JavaScriptSerializer js = new JavaScriptSerializer();
        Context.Response.Write(js.Serialize(listaTaskova));
    }

Why asmx work on server and localhost but not from web browser?

  • I've never used `Context.Response.Write(js.Serialize(listaTaskova));` so i'm not sure about that, but could you just return a string and see if that works? – wazz Jul 22 '19 at 04:39
  • Also, an asmx response is returned in a wrapper and the way to your data is not just `result` but `result.d`. Some more possible help here: https://stackoverflow.com/questions/8550530/response-write-in-webservice. – wazz Jul 22 '19 at 04:45

1 Answers1

0

An asmx response is returned in a wrapper-object, always called d, and the way to access the data is not just result but result.d.

Some more possible help here: Response.Write() in WebService.

wazz
  • 4,953
  • 5
  • 20
  • 34
  • Thanks for answers...Its not problem with data..on server all work just fine...but when you open app from browser..like you type url of server on browser..and app open...in that case I have error POST internal server error 500...And that is somethink between Server client and asmx web method – Cristiano Azarnowski Jul 22 '19 at 23:01
  • I see. I don't think anyone can tell the answer from what's posted so far. More details on the error might help. – wazz Jul 23 '19 at 02:51