-1

Why oh why doesn't this code do Anything?! What is wrong with my ajax? My ajax:

$.ajax({
                type: "POST",
                url: "/index.aspx/Uppdatera",
                data: "{ Id:"+ JSON.stringify($item.Id) +" }",
                error: 
                    alert("error")
            });

My C#:

 [WebMethod(EnableSession = true)]
        public static void Uppdatera(object id)
        {
            id.ToString();
            using (StreamWriter s = new StreamWriter("C:/Users/robert/Documents/visual studio 2013/Projects/GolvProjektet/GolvProjektet/hej.txt"))
            {
                s.Write("hej" + id);
            }
        }
user3581054
  • 125
  • 12
  • you have to use Firebug and click on 'net' and read your ajax request and responses. – prospector Dec 22 '14 at 16:38
  • I am sure that something happens, have you debugged? Have you check in something like fiddler or browser dev tools to see what the request is doing? – Ben Robinson Dec 22 '14 at 16:39
  • What's it meant to do? We can't help if you don't explain what the desired behaviour is, what it's doing instead, and what you've already tried. – ArtOfCode Dec 22 '14 at 16:39
  • At the moment, I am just trying to make the WebMethod work, and after that I will work on what it will do :) I am clicking a button, and then my ajax is running. But the file hej.txt is not created. – user3581054 Dec 22 '14 at 16:41
  • @prospector I get error code 301: Move Permanently. – user3581054 Dec 22 '14 at 16:45

1 Answers1

0

Add the contentType y dataType in ajax call:

$.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                url: "/index.aspx/Uppdatera",
                data: "{ Id:"+ JSON.stringify($item.Id) +" }",
                error: 
                    alert("error")
            });
Eduardo Vélez
  • 193
  • 1
  • 4