views:

91

answers:

1

I have a url like: http://localhost:8080/myapp/discussions/voteup?id=1

which returns the following json:

{"vote":{"value":"100"}}

I am trying to make a JQuery Ajax Call to post a vote to the url.

$(function(){
 $(".vote-up-post").click(function() {
        var postId = $("#postId");
        alert("Post Value" + postId.val());
        $.ajax({
           type: "GET",
           url: "/myapp/discussions/voteup",
           data: {'id': postId.val()},
           dataType: "json",
           success: function(response){
             $(".post-votes-count").text("100");
           },
           error: function(response){
             alert("Error:" + response);
           }
        });
 });
});

I get the the following pop up for the second alert message:

Error:[object XMLHttpRequest]

Any idea what I am missing?

+5  A: 

Your error function should be:

error: function(req, response) {
    alert("Error:" + response);
}

The first argument of the error function is the XMLHttpRequest object that was used to make the ajax request. The second argument will give you the status of the object: "timeout", "error", "notmodified" or "parsererror."

jimyi