2009-08-20 31 views
1

幫助,我需要改變這個代碼來支持遠程域的訪問:在你返回JS轉換XMLHttpRequest來JSONP

function goRemote(url) { 
    var script = document.createElement("script"); 
    script.src=url; 
    document.body.appendChild(script); 
} 
function parseDate(json) { 
    // do your fun here. 
} 

:在你的js

document.write(url); 
    var http = getHTTPObject(); 
     http.open("GET", url, true); 
     http.onreadystatechange = function() { 
      if (http.readyState == 4) { 
       parseData(http.responseText); 
      } 
     } 
     http.send(null); 

回答

4

parseData({"foo": "bar"}); 
+0

實際上,HEAD標籤在HTML4.01中不能具有「id」屬性。相反,使標記無效並通過ID訪問HEAD元素,請使用'getElementsByTagName('head')[0]'(或任何類型的可用選擇器實用程序,如jQuery中的''',Prototype.js中的$$'等) – kangax 2009-08-20 13:26:41

+0

返回的js樣本無效.. – Tom 2009-08-20 13:28:19

+0

獲取元素頭不工作.. – Tom 2009-08-20 13:32:48