0

Hi i try to send a parameter to my Webservice to get the Data. But iam getting always an Error: [object Error]

Error-Snapshot

What does that Error means?

The Webservice is working so far. If i Invoke the Webmethod in the Browser i get all the data.

What iam doing wrong. I have tried many things, but nothing helped.. Hope you can help me

My Query:

    function loadDate() {

        jQuery.support.cors = true;
        PanelID = document.getElementById('PanelID').value;
        alert(PanelID);


        jQuery.ajax({
            type: "POST",
            url: "http://nexxt-entwicklung.de/Web/Service1.asmx/getDatetime",
            data: "{ 'PanelID': '" + PanelID + "' }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                alert("Success: " + msg.d);

            },
            error: function(msg) {
                alert("Failed: " + msg.status + ": " + msg.statusText);

            }
        });   
    }

My Webservice:

 [ScriptService]
public class Helper
{
    public class VERANSTALTUNGEN
    {
    public string Von { get; set; }
    public string Bis { get; set; }
    public string Thema { get; set; }
    public string PanelIDs { get; set; }
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static List<VERANSTALTUNGEN> getDatetime(string PanelID)
        {

            List<VERANSTALTUNGEN> Besprechungen = new List<VERANSTALTUNGEN>();

            StringBuilder query = new StringBuilder("SELECT DISTINCT r.PanelID AS PANEL_ID, rr.Von AS DATEVON, rr.Bis AS DATEBIS, b.THEMA AS BESPRECHUNGSTHEMA FROM RAUM r right join RESERVIERUNGRAUM rr ON r.ID = rr.Raum_ID right join BUCHUNG b ON rr.BUCHUNG_ID = b.ID where r.PANELID = @ID ORDER BY rr.VON");

            using (SqlConnection con = new SqlConnection(@"Data Source=Localhost\SQLEXPRESS;Initial Catalog=BOOK-IT_LH;Integrated Security=true;"))
            using (SqlCommand cmd = new SqlCommand(query.ToString(), con))
            {
                cmd.Parameters.Add("@ID", System.Data.SqlDbType.Char);
                cmd.Parameters["@ID"].Value = PanelID;
                con.Open();

                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        if (rdr["DATEVON"] != DBNull.Value && rdr["DATEBIS"] != DBNull.Value)
                        {
                            Besprechungen.Add(new VERANSTALTUNGEN()
                            {
                                Von = rdr["DATEVON"].ToString(),
                                Bis = rdr["DATEBIS"].ToString(),
                                Thema = rdr["BESPRECHUNGSTHEMA"].ToString(),
                                PanelIDs = rdr["PANEL_ID"].ToString()
                            });
                        }
                    }
                }
            }
            return Besprechungen;
     }
}

Webservice Method

[System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public List<Helper.VERANSTALTUNGEN> getDatetime(string PanelID)
        {
            return Helper.getDatetime(PanelID);
        }
    }
1
  • Now i opened the url with STRG+Mouse click in visual studio. I get an Http 500 error. But in the browser the url works? Could that be the Problem? Commented Sep 20, 2012 at 9:12

2 Answers 2

0

It means that msg.statusText is an object that is an instance of Error.

Use console.log instead of alert to see what the object contains in a console in Chrome/Firebug, or loop through the object and alert each key/value.

Sign up to request clarification or add additional context in comments.

1 Comment

i tried with firebug now, but it only shows failed : 0 : error
0

When it comes to the problem itself, while using dataType json:

you shouldn't do:

data: "{ 'PanelID': '" + PanelID + "' }",

but rather something like

data: { 'PanelID': PanelID },

cause otherwise instead of posting some object you're sending string

do always make sure you read the specs: http://api.jquery.com/jQuery.ajax/

4 Comments

then probably you should read David's hint and try to verify what is the Error even saying. You could also debug the c# code to check what is happening there - whether the parameters you're passing are correctly mapped. The error could be caused not only by the JS side, by also by the Webservice throwing exception.
i added a comment to my question, can you look at it please
you could install firebug. go to tab script - enable it - reload the page - find there your script alert("Failed: ... add there a breakpoint (clicking on the left from the line numbers) - trigger the event. Then after the breakpoint is hit, go to console and inspect the msg element (just type msg in console and browse the result). Then you can probably see the internal error message
if you searched for the problem on stack you could actually find: stackoverflow.com/questions/6463028/… which states that while using .net webservices u should be looking at msg.d.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.