2015-07-20 54 views
0

我在嘗試使用yql語句時收到錯誤消息。控制檯說有語法錯誤,但我沒有看到錯誤。我已經發布了所有的代碼,因此可以複製並粘貼以重複該錯誤。訪問Yahoo 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>

回答

1

我發現我有錯誤。這是現在的正確路線:

var data = encodeURIComponent("select * from yahoo.finance.historicaldata where symbol = '" + symbol + "' and startDate = '" + dateInput + "' and endDate = '" + dateInput + "'");