开发者

JQuery Ajax call

开发者 https://www.devze.com 2022-12-20 16:07 出处:网络
I have a url like: http://localhost:8080/myapp/discussions/voteup?id=1 which returns the following json:

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: func开发者_运维百科tion(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?


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."

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号