尝试使用yql语句时收到错误。控制台说有语法错误,但我没有看到错误。我已经发布了所有代码,因此可以复制并粘贴以重复错误。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Finances</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script language="JavaScript">
function start(){
getData();
// document.getElementById('link1').click();
}
function getData() {
var url = "http://query.yahooapis.com/v1/public/yql";
var symbol = $("#symbol").val();
var dateInput = $("#dateInput").val();
var data = encodeURIComponent("select * from yahoo.finance.historicaldata where symbol = '"symbol"' and startDate = '"dateInput"' and endDate = '"dateInput"'");
$.getJSON(url, '?q=' + data + "&diagnostics=true&env=store://datatables.org/alltableswithkeys")
.done(function (data) {
$("#name").text(data.query.results.quote.Symbol);
$("#date").text(data.query.results.quote.Date);
$("#close").text( data.query.results.quote.Close);
}).fail(function (jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
$("#result").text('Request failed: ' + err);
});
}
function SendRequest()
{
getData();
// document.getElementById('link1').click();
}
function CheckEnter(e)
{
if ((e.keyCode && e.keyCode==13) || (e.which && e.which==13)) {
return SendRequest();
}
return true;
}
</script>
</head>
<body style="margin: 0px;" bgcolor="#678fc2" onload="start();">
<table width="90%" border="0" cellpadding="0" cellspacing="0" align="center">
<tbody>
<tr valign="top">
<td class="normalText" align="left">
<label>Date</label>
<input name="date" id="dateInput" value="2010-07-17" type="text" />
<br/>
<label>Ticker Symbol</label>
<input name="txtQuote" id="symbol" onkeypress="return CheckEnter(event);" value="YHOO" type="text" />
<input name="button" type="button" id="btnQuote" onclick="return SendRequest();" value="Get Quotes" />
<br />
<div id="service" style="padding:10px 0;">
<table style="border: 1px solid black;" width="770">
<tbody>
<tr style="font-size: 14px; font-family: Arial,Helvetica,sans-serif; font-weight: bold; padding: 0px 2px;">
<td>Symbol</td>
<td>Date</td>
<td>Closing Price</td>
</tr>
<tr style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; padding: 0px 2px;">
<td id="name"></td>
<td id="date"></td>
<td id="close"></td>
</tr>
</tbody>
</table>
<br /><br />
</div>
</td>
</tr>
</tbody>
&#13;
答案 0 :(得分:1)
我发现了我遇到的错误。这是正确的行:
var data = encodeURIComponent("select * from yahoo.finance.historicaldata where symbol = '" + symbol + "' and startDate = '" + dateInput + "' and endDate = '" + dateInput + "'");