- Home /
 
               Question by 
               Thromshall · Jan 03, 2014 at 06:12 AM · 
                functiondelegatecallbackexecute  
              
 
              Callback never gets executed
So I am trying to post to my web api and use a callback when the post finishes. This all works perfectly in the Unity editor and as a Desktop app, but does NOT work in the Web Player. I have narrowed it down to just the callback not actually getting called. How can I use callbacks? Here is my code:
void ui_login() { if (uiBase == null) return; Debug.LogError(uiBase); clicks++; status = "(" + clicks + ")" + "working";
     var username = uiBase.UIElements.FirstOrDefault(e => e.Name == "txt_username");
     var password = uiBase.UIElements.FirstOrDefault(e => e.Name == "txt_password");
     try
     {
         var request = new LoginRequest()
         {
             Email = username.Text,
             Password = password.Text
         };
         StartCoroutine(WaitForRequest<LoginResponse>(request, loginCallback));
     }
     catch (Exception e)
     {
         status = "(" + clicks + ")" + e;
     }
 }
 void loginCallback(LoginResponse response, WWW www)
 {
     if (www.error != null)
         status = www.error;
     if (response != null)
         status = response.ErrorMessage;
 }
 IEnumerator WaitForRequest<TResponse>(LoginRequest request, Action<TResponse, WWW> callback)
 {
     var json = JsonMapper.ToJson(request);
     var www = new WWW("http://someurl.com", json.ToBytes());
     yield return www;
     TResponse response;
     if (www.error == null && www.isDone)
     {
         var str = Encoding.UTF8.GetString(www.bytes);
         print(str);
         status = str;
         response = JsonConvert.DeserializeObject<TResponse>(str);
     }
     else
         response = default(TResponse);
     print("somthif");
     callback(response, www);
 }
               Comment
              
 
               
              Your answer
 
 
             