【发布时间】:2015-03-01 14:27:34
【问题描述】:
尝试执行解析时,我通过调试器意外收到以下错误。
Uncaught ReferenceError: Parse is not defined
我很确定它的定义很好,所以不确定错误来自哪里。
基本上这里发生的事情是使用谷歌 url 缩短将长 url 转换为短 url,然后解析抓取缩短的 url 并将其存储。
<html>
<head>
</head>
<script type="text/javascript">
function makeShort()
{
var longUrl=document.getElementById("longurl").value;
var request = gapi.client.urlshortener.url.insert({
'resource': {
'longUrl': longUrl
}
});
request.execute(function(response)
{
if(response.id != null)
{
str ="<a href='"+response.id+"'>"+response.id+"</a>";
document.getElementById("output").innerHTML = str;
Parse.initialize("ID", "ID");
var PDFUpload = new Parse.Object("Scan");
PDFUpload.set("PDFDocument", str);
PDFUpload.save(null,
{
success: function(uploadResult) {
// Execute any logic that should take place after the object is saved.
},
error: function(uploadResult, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and description.
alert('Failed to create new object, with error code: ' + error.description);
}
});
}
else
{
alert("error: creating short url");
}
});
}
function load()
{
gapi.client.setApiKey('ID'); //get your ownn Browser API KEY
gapi.client.load('urlshortener', 'v1',function(){});
}
window.onload = load;
</script>
<script src="https://apis.google.com/js/client.js"> </script>
<body>
URL: <input type="text" id="longurl" name="url" value="yahoo.com" /> <br/>
<input type="button" value="Create Short" onclick="makeShort();" /> <br/> <br/>
<div id="output"></div>
</body>
</html>
特别是,下面是发生的对话,以及我尝试存储要解析的 url:
if(response.id != null)
{
str ="<a href='"+response.id+"'>"+response.id+"</a>";
document.getElementById("output").innerHTML = str;
Parse.initialize("ID", "ID");
var PDFUpload = new Parse.Object("Scan");
PDFUpload.set("PDFDocument", str);
PDFUpload.save(null,
{
success: function(uploadResult) {
// Execute any logic that should take place after the object is saved.
},
error: function(uploadResult, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and description.
alert('Failed to create new object, with error code: ' + error.description);
}
});
}
【问题讨论】:
-
如果浏览器告诉你“Parse”没有定义,是什么让你这么确定呢?
-
因为我在其他地方使用过相同的代码,而且它似乎工作正常。我认为这可能是由于它的放置位置。
-
如果您能以任何方式提供帮助,我将不胜感激
-
您是否应该从 parse.com 导入一些脚本?我在您发布的代码中没有看到类似的内容。
标签: javascript url url-rewriting parse-platform google-drive-api