$.ajax using JsonResult - Returns “toJSON - function (key) { return this.valueOf(); }”

Here is what I have:

Controller
  [HttpPost]
  public ActionResult GetNumbers(int id)
  {
      List<int> privIDs = new List<int>();
      //My Numbers!                
      privIDs.Add(2);
      privIDs.Add(3);
      return Json(privIDs);
  }
Javascript
    var id = 1;
    url = "/Home/GetNumbers/";
    var getData = {
        'Id': id
    };
    $.ajax({
        type: "POST",
        url: url,
        data: getData,
        dataType: "json",
        success: function (result) {
            $.each(result, function () {
                $.each(this, function (index, data) {
                    alert(index + " - " + data);
                });
            });
        },
        error: function (request, status, error) {
            alert("fail");
        }
    });
The Result

Two alert boxes both containing:

toJSON - function (key) { return this.valueOf(); }
The Question

Where are my numbers? (2 & 3 in this example...)

EDIT

I swear I did this before. But this is what i was after..

                    success: function (result) {
                        $.each(result, function (index, value) {
                            alert(index + ': ' + value);
                        });
                    },

Answers


remove your code and just try this , just for testing , if it works just write a loop statement

success: function (result) {
            // loop through this
            result.privIDs[0]
        },

Need Your Help

Length of h:outputLabel changes after RichFaces AJAX call

jsf richfaces ajax4jsf

I have been trying to incorporate RichFaces into one of our more complicated pages to make it run a bit more smoothly via AJAX. Everything is working fine and it has solved a few problems I was hav...

Pagefile-backed memory-mapped files vs. Heap — what's the difference?

c++ c winapi heap memory-mapped-files

What is the advantage of using a memory-mapped file backed by the system paging file (through CreateFileMapping(INVALID_HANDLE_VALUE, ...), instead of just allocating memory from the heap the usual...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.