I'm trying to make jQuery Autoplete, Yahoo Finance and Zend Framework work together.
What I want is to create a form field in which I can autoplete tickers symbols through Yahoo API.
I've already created a Zend_From element that contains this :
$this->setJQueryParam('source', new Zend_Json_Expr('function( request, response ) {
$.ajax({
type: "GET",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "YAHOO.Finance.SymbolSuggest.ssCallback",
data: {
query: request.term
},
cache: true,
url: "";
}
});
}'));
$this->getView()->jQuery()->addJavascript('var YAHOO={Finance:{SymbolSuggest:{}}};');
$this->getView()->jQuery()->addOnLoad('YAHOO.Finance.SymbolSuggest.ssCallback = function (data) {
console.log(JSON.stringify(data)); }');
I found this post that resolved a part of my problem, but I think using var YAHOO={Finance:{SymbolSuggest:{}}};
is a dirty trick and isn't the right way to do.
Now, if I type GOO in my field, then the firebug console will show me something like this:
{"ResultSet":{"Query":"goo","Result":[{"symbol":"GOOG","name":"Google Inc.","exch":"NMS","type":"S","exchDisp":"NASDAQ","typeDisp":"Equity"},{"symbol":"GT","name":"Goodyear Tire & Rubber Co.","exch":"NYQ","type":"S","exchDisp":"NYSE","typeDisp":"Equity"}...
which is great, but I don't know how to send back these data to Autoplete from this callback function, any idea?
I'm trying to make jQuery Autoplete, Yahoo Finance and Zend Framework work together.
What I want is to create a form field in which I can autoplete tickers symbols through Yahoo API.
I've already created a Zend_From element that contains this :
$this->setJQueryParam('source', new Zend_Json_Expr('function( request, response ) {
$.ajax({
type: "GET",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "YAHOO.Finance.SymbolSuggest.ssCallback",
data: {
query: request.term
},
cache: true,
url: "http://autoc.finance.yahoo./autoc";
}
});
}'));
$this->getView()->jQuery()->addJavascript('var YAHOO={Finance:{SymbolSuggest:{}}};');
$this->getView()->jQuery()->addOnLoad('YAHOO.Finance.SymbolSuggest.ssCallback = function (data) {
console.log(JSON.stringify(data)); }');
I found this post that resolved a part of my problem, but I think using var YAHOO={Finance:{SymbolSuggest:{}}};
is a dirty trick and isn't the right way to do.
Now, if I type GOO in my field, then the firebug console will show me something like this:
{"ResultSet":{"Query":"goo","Result":[{"symbol":"GOOG","name":"Google Inc.","exch":"NMS","type":"S","exchDisp":"NASDAQ","typeDisp":"Equity"},{"symbol":"GT","name":"Goodyear Tire & Rubber Co.","exch":"NYQ","type":"S","exchDisp":"NYSE","typeDisp":"Equity"}...
which is great, but I don't know how to send back these data to Autoplete from this callback function, any idea?
Share Improve this question edited May 23, 2017 at 12:05 CommunityBot 11 silver badge asked Feb 8, 2012 at 10:54 LiyaliLiyali 5,6932 gold badges28 silver badges41 bronze badges 5- Here is a good way to quickly try the yahoo finance lookup api: d.yimg./autoc.finance.yahoo./… – Liyali Commented Feb 8, 2012 at 10:57
- I'll add a caution that this autoplete functionality provided by autoc.finance.yahoo. is not a real API - it's an internal Yahoo function for their websites. You can certainly play with and build apps with it, but I wouldn't try to build anything real with it or you may run against their terms of service. – BrianC Commented Feb 8, 2012 at 23:13
- Thanks for your ment, I'm actually developing a virtual portfolio manager. – Liyali Commented Feb 9, 2012 at 6:49
- did you run into any issues due to the tos BrianC is mentioning? – HBCondo Commented Mar 22, 2012 at 5:55
- None so far, I even ran a cron process to see how many requests Yahoo could handle from the same server, and it seems that one request every 8 sec (for 3 days) worked pretty good. – Liyali Commented Mar 23, 2012 at 9:45
2 Answers
Reset to default 4Liyali, thanks for figuring it out and posting the code. I just wanted to provide the js in the context of a jquery auto-plete:
$("#txtTicker").autoplete({
source: function (request, response) {
$.ajax({
type: "GET",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "YAHOO.Finance.SymbolSuggest.ssCallback",
data: {
query: request.term
},
cache: true,
url: "http://autoc.finance.yahoo./autoc"
});
YAHOO.Finance.SymbolSuggest.ssCallback = function (data) {
response($.map(data.ResultSet.Result, function (item) {
return {
label: item.name,
value: item.symbol
}
}));
}
},
minLength: 1,
select: function (event, ui) {
$("#txtTicker").val(ui.item.name);
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
I have finally found a solution, but I'm still using YAHOO namespace though.
I first removed the last line (addOnLoad) and move its content right after the Ajax request so that I'm still into the autoplete function and I can return the result to autoplete.
Here is the final code:
$this->setJQueryParam('source', new Zend_Json_Expr('function( request, response ) {
$.ajax({
type: "GET",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "YAHOO.Finance.SymbolSuggest.ssCallback",
data: {
query: request.term
},
cache: true,
url: "http://autoc.finance.yahoo./autoc";
}
});
YAHOO.Finance.SymbolSuggest.ssCallback = function (data) {
console.log(data.ResultSet.Result);
response( $.map( data.ResultSet.Result, function( item ) {
return {
label: item.symbol,
value: item.name
}
}))
}
}'));
$this->getView()->jQuery()->addJavascript('var YAHOO={Finance:{SymbolSuggest:{}}};');
Hope it can help!