2015-06-23 21 views
2

我試圖用這個代碼Parse.Cloud.beforeSave ...Parse.com錯誤使用了document.createElement( '腳本')

var script = document.createElement('script'); 

,我得到這樣的:結果:的ReferenceError:文件未定義

如何使用文件與Parse.Cloud?

我的代碼:

function getJSONP(url, success) { 
     var script = document.createElement('script'); 
     script.src = url.replace('callback=', 'callback=do'); 
     document.head.appendChild(script); 

     do = function (data) { 
      success(data); 
     } 
} 
+2

解析雲代碼不會在瀏覽器中運行。它在DOM不存在的服務器上運行。你爲什麼試圖使用DOM? –

+0

我試圖下載一個JSONP ...函數getJSONP(url,成功){var_type = document.createElement('script'); script.src = url.replace('callback =','callback = do'); document.head.appendChild(script); do = function(data){ console.log(data); 成功(資料); } } – Geek20

+0

不確定Parse是否允許,但是您可以只做一個正常的HTTP請求和'eval'響應。 JSONP僅用於規避瀏覽器中的同源策略。在服務器端不需要腳本標記,只需發出HTTP請求即可。 –

回答

0

解決辦法:

Parse.Cloud.httpRequest({ 
    url: myURL, 
    success: function(httpResponse) { 
     console.log(httpResponse.data); 
     response.success(); 
    }, error: function(httpResponse) { 
     response.error('Request failed...'); 
    } 
});