2014-12-13 146 views
-2

我试图从JavaScript发送JSON对象到Flex,我接收到“空”,发送JSON对象到Flex

下面是我使用的呼叫从柔性JavaScript方法的代码:

private function checkUpdate():void { 
    if (ExternalInterface.available) { 

     var jsonObject:Object = ExternalInterface.call("getWhatsNew"); 

     Alert.show(jsonObject.toString()); //shows NULL 
    } 
} 

这里是Java脚本代码:

function getWhatsNew() { 
$.ajax({ 
    type: 'POST', 
    url: 'http://10.76.116.54:8080/whatsnew', 
    data: null, 
    dataType: 'json', 
    async: false, 
    success: function (response) { 
     return response; 
    } 
}); 
} 

什么是做了正确的方法是什么?

+1

是否必须使用javascript才能做到这一点? – Astyan 2014-12-15 08:55:06

回答

0

显然你需要从你的getWhatsNew()函数返回一些东西。你的代码的工作证明是与此相同:

function getWhatsNew() { 
    $.ajax({ 
     type: 'POST', 
     url: 'http://10.76.116.54:8080/whatsnew', 
     data: null, 
     dataType: 'json', 
     async: false, 
     success: function (response) { 
      return response; 
     } 
    }); 
    return null; 
} 

你可以解决这个问题通过添加以下到您的SWF的初始化:

ExternalInterface.addCallback("receiveUpdate", receiveUpdate); 

而且你的Ajax“成功”的功能:

success: function (response) { 
    getSWF("whatsNewSWF").receiveUpdate(response); 
} 

查看Adobe documentation了解更多详情。