curt

curt


  • Name: [not set]
  • Favorite Languages: [not set]
  • Website: [not set]
  • Location: [not set]
  • About Me: [not set]

Recent Comments

  • XML Parsing with jQuery
    12/07/2011 - 23:22

    That seems weird that if you enter this URL:

    http://www.google.com/ig/api?stock=.ftse

    into your browser, it works fine and shows you the XML data.

    But, if you use that URL in Javascript, then you get the cross-domain issue. Do you know why? In both scenarios, it's the client's machine that is trying to access Google.

  • XML Parsing with jQuery
    12/06/2011 - 11:25

    Thanks for your help!

    I found the console and it had this message:

    "XMLHttpRequest cannot load http://www.google.com/ig/api?stock=.ftse. Origin http://vomad.com is not allowed by Access-Control-Allow-Origin."

    What's interesting is that I changed the URL from:

    http://www.google.com/ig/api?stock=.ftse

    to

    http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AAPL%22)&env=store://datatables.org/alltableswithkeys

    and I no longer get the XMLHttpRequest message anymore.

    Would you know why this happens with Google's URL but not Yahoo's URL?

    FYI, I had changed this

    success: parseXml,

    to this

    success: parseXml(xml),

    and I no longer get the previous error message. I get this:

    executed parseXML

    which means that the parseXml function is getting executed at least, which it wasn't before.

  • XML Parsing with jQuery
    12/05/2011 - 19:09

    Am I correct to assume that you are replying to my posting?

    How do I view my browser's error console? (I'm using Google Chrome)

    You wrote: "My guess is that this is a cross-domain issue. Most of the time javascript cannot make callbacks to a domain that is different than the one hosting the javascript."

    Where in my code is it making a callback? I'm not sure I understand what you mean. Are you referring to the line that has the URL to the web service providing the XML file?

    $.ajax({
                            type: "GET",
                            url: "http://www.google.com/ig/api?stock=.ftse",
                            dataType: "xml",
                            success: parseXml,
                            //error: err
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                            $("#output").append(XMLHttpRequest.responseText + "<br />TextStatus: " + textStatus + "<br />ErrorThrown: " + errorThrown);
                            }
                      });

    I have the Javascript file (jquery.js) residing on the same webserver as the index.html file.

  • XML Parsing with jQuery
    12/05/2011 - 17:17

    I'm trying to read and parse a XML file from Google Finance API:

    http://www.google.com/ig/api?stock=.ftse

    <xml_api_reply version="1">
    <finance module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
    <symbol data=".FTSE"/>
    <pretty_symbol data=".FTSE"/>
    <symbol_lookup_url data="/finance?client=ig&q=.FTSE"/>
    <company data="FTSE 100"/>
    <exchange data="INDEXFTSE"/>
    <exchange_timezone data=""/>
    <exchange_utc_offset data=""/>
    <exchange_closing data=""/>
    <divisor data="2"/>
    <currency data="GBP"/>
    <last data="5567.96"/>
    <high data="5602.80"/>
    <low data="5545.93"/>
    <volume data="0"/>
    <avg_volume data=""/>
    <market_cap data=""/>
    <open data="5552.44"/>
    <y_close data="5552.29"/>
    <change data="+15.67"/>
    <perc_change data="0.28"/>
    <delay data="15"/>
    <trade_timestamp data="4 hours ago"/>
    <trade_date_utc data="20111205"/>
    <trade_time_utc data="163530"/>
    <current_date_utc data="20111205"/>
    <current_time_utc data="212935"/>
    <symbol_url data="/finance?client=ig&q=.FTSE"/>
    <chart_url data="/finance/chart?q=INDEXFTSE:.FTSE&tlf=12"/>
    <disclaimer_url data="/help/stock_disclaimer.html"/>
    <ecn_url data=""/>
    <isld_last data=""/>
    <isld_trade_date_utc data=""/>
    <isld_trade_time_utc data=""/>
    <brut_last data=""/>
    <brut_trade_date_utc data=""/>
    <brut_trade_time_utc data=""/>
    <daylight_savings data="false"/>
    </finance>
    </xml_api_reply>

    I have this Javascript:

    <script type="text/javascript" src="../jquery.js"></script>
    <script type="text/javascript">
                                   
            $(document).ready(function()
                    {
                      $.ajax({
                            type: "GET",
                            url: "http://www.google.com/ig/api?stock=.ftse",
                            dataType: "xml",
                            success: parseXml,
                            //error: err
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                            $("#output").append(XMLHttpRequest.responseText + "<br />TextStatus: " + textStatus + "<br />ErrorThrown: " + errorThrown);
                            }
                      });
                      /* document.write("loaded XML file"); */
                    });
                   
            function err(xhr, reason, ex)
                    {
                      $('#output').append(reason);
                    }
                   
            function parseXml(xml)
                    {
                      //find every last and print the value
                      $(xml).find("last").each(function()
                              {
                                    $("#output").append($(this).attr("data") + "<br />");
                              });
                      document.write("executed parseXML");
                   
                    }
    </script>

    However, I get an error:

    TextStatus: error
    ErrorThrown:

    Can anybody help solve the problem?