客户端restful jQuery不起作用

时间:2013-11-21 12:49:54

标签: jquery rest-client

我的想法是创建一个函数来返回休息服务中的调用值。

来自内部功能的代码:

.....

var dddd;
 $.ajax({
     type: "GET",
     url: "http://localhost:8084/GetSomeRest/asdf/ddd/arbol/1",  
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     async: "false", // with this line add solved
     success: function (dataaa) {
         // do something
       dddd= dataaa.name;
         alert(dddd);// here has value
     }}); 
alertt(dddd); //here is null
.....

有什么问题?欢迎任何帮助。

1 个答案:

答案 0 :(得分:0)

var dddd;

 $.ajax({
     type: "GET",
     url: "http://localhost:8084/GetSomeRest/asdf/ddd/arbol/1",  
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     success: function (dataaa) {
         // do something
       dddd= dataaa.name;
         alert(dddd);// here has value
     }}); 
alert(dddd); --> this is fired before assigning value through ajax

在ajax调用之外调用该警报时,Ajax调用未完成