2013-11-21 102 views
-1

我的想法是創建一個函數,它返回休息服務時的呼叫值。從內部功能客戶端restful jQuery不起作用

代碼:

..... 

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

問題是什麼?歡迎任何幫助。

+0

可能重複[如何返回從AJAX響應調用?](http://stackoverflow.com/questions/14220321/how-to-return-the-an-ajax-call) –

回答

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調用未完成

+0

我該如何解決它? – user1949142