开发者

Accessing REST Web Services through JavaScript

First of all. I want to say that i've acctualy read the other posts (like this) but, i don't thin开发者_如何学编程k it's a good answer. I mean, what about all the status codes, and HyperMedia, etc. What about caching?

What do you think?


I agree you do need error handling etc. I've been using Dojo, here's code from my blog

var myEdition = {"Edition":{“author”:”x”, “title”"isbn":"44"}};
      var xhrArgs = {
                url: http://myhost/LibraryWink/library/editions,
                postData: dojo.toJson(myEdition),
                handleAs: "json",
                headers: { "Content-Type": "application/json"},
                load: function(data) {
                    dojo.byId("mainMessageText").innerHTML
                           =  "Message posted.";
                },
                error: function(error) {
                    dojo.byId("mainMessageText").innerHTML
                            = "Error :" + error;
                }
            };
        dojo.byId("mainMessageText").innerHTML
                           = "Message being sent…"; 
        var deferred = dojo.rawXhrPost(xhrArgs);

The relevent points here being a). a framework such as dojo (orI guess jquery) helps b). there is handling for errors.

I also have some thoughts in general about REST services and error handling.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜