2013-02-13 175 views
0

我对Jquery颇为新颖,colorbox更是特别。 我使用下面打开颜色框:以json格式从colorbox获取数据

jQuery().colorbox({ 
     href: 'http://example.com#oslc-core-postMessage-1.0', 
     iframe:true, 
     width:"1100px", 
     height:"80%" 
    }); 

的颜色框内提交信息后,我正在以下,如果我使用iframe:

{"oslc_cm:message":"oslc_cm:create","oslc_cm:results":[{"oslc_cm:label":"TA41071:Test", "rdf:resource":"https://example.com/TA41071"}]} 

问题是:如何能我从colorbox获取json值?现在,colorbox保持打开状态,空白,没有任何反应。

回答

0

我可以通过以下操作来获得JSON:

function createListener() 
{ 
window.addEventListener('message', 
    function (event) { 
    try { 
    jQuery().colorbox.close(); 
    var message = event.data; 
    if (message.indexOf("oslc-response:")>-1) { 
     message=message.substring(14); 
    } else { 
     alert('Error. return message should start with "oslc-response:".'); 
     return; 
    } 
    handleMessage(message); 
    } catch (e) { 
    // ignore: access exception when trying to access window name 
    } 
    } 
, false); 
} 

(function($) 
{ 
$(document).bind('cbox_load', createListener());   
}) (jQuery); 
相关问题