jquery
  • json
  • getjson
  • 2012-03-07 14 views 0 likes 
    0

    で動作します。それはIEを(作品

    <button>show</button><br /> 
    
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function(){ 
    var url='http://weather.yahooapis.com/forecastjson?w=2344116&u=c'; 
    var query; 
        $('button').click(function(){ 
         $.getJSON(url, function(json) { 
         alert(json.units.temperature); 
         }); 
        }); 
    }); 
    </script> 
    

    を私は警告ポップアップを得ている)、それはクロムとFirefoxで動作しません。また、JSONの出力を検証しました。

    { 
        "units": { 
         "temperature": "C", 
         "speed": "km/h", 
         "distance": "km", 
         "pressure": "mb" 
        }, 
        "location": { 
         "location_id": "TUXX0014", 
         "city": "Istanbul", 
         "state_abbreviation": "*", 
         "country_abbreviation": "TU", 
         "elevation": 92, 
         "latitude": 41.01, 
         "longitude": 28.95 
        }, 
        "wind": { 
         "speed": 10, 
         "direction": "NE" 
        }, 
        "atmosphere": { 
         "humidity": "34", 
         "visibility": 9.99, 
         "pressure": 1016, 
         "rising": "steady" 
        }, 
        "url": "http://weather.yahoo.com/forecast/TUXX0014.html", 
        "logo": "http://l.yimg.com/a/i/us/nt/ma/ma_nws-we_1.gif", 
        "astronomy": { 
         "sunrise": "06:29", 
         "sunset": "18:03" 
        }, 
        "condition": { 
         "text": "Fair", 
         "code": "34", 
         "image": "http://l.yimg.com/a/i/us/we/52/34.gif", 
         "temperature": 9 
        }, 
        "forecast": [ 
         { 
          "day": "Today", 
          "condition": "Mostly Sunny", 
          "high_temperature": 8, 
          "low_temperature": 2 
         }, 
         { 
          "day": "Tomorrow", 
          "condition": "Mostly Cloudy", 
          "high_temperature": 8, 
          "low_temperature": 3 
         } 
        ] 
    } 
    

    助けてください。

    よろしくお願いいたします。

    オスマン。

    +0

    を試してみてください。 – steveoh

    答えて

    0

    私がいることを試してみました:http://jsfiddle.net/arXt2/と私のエラーログは言う:あなたが欲しい

    XMLHttpRequest cannot load http://weather.yahooapis.com/forecastjson?w=2344116&u=c. 
    Origin http://fiddle.jshell.net is not allowed by Access-Control-Allow-Origin. 
    

    cross side scriptingです。 How to make an ajax with JQuery with cross site scripting?

    +0

    プロキシを有効にするためにサーバーサイドスクリプトを作成する必要があるようです。 私はsharepoint環境に取り組んでいます。私はpage_load関数で次のコードを追加しましたが、何も起こりませんでした。私はまだ問題を抱えています:( Response.AppendHeader( "Access-Control-Allow-Origin"、 "*"); –

    0

    Cross-Originブラウザの問題を参照してください。詳細情報については

    http://enable-cors.org/

    は、それが私のChromeとFirefoxで `アクセス制御 - 許可 - Origin`障害を与えるjsFiddleでこれをしようと Using the Yahoo Weather API with JSON and the script tag

    +0

    あなたの素早い返信のためのLucaありがとうございます。スクリプトのタグは問題ですが、引き続き問題が続きます 奇妙なこと似たようなスクリプトでtwitterやflickrからデータを解析することができます –

    +0

    私はプロキシを有効にするためにサーバー側のスクリプトを作成する必要があるようです 私はsharepoint環境で作業しています。私はまだ問題が発生しています:( Response.AppendHeader( "Access-Control-Allow-Origin"、 "*"); –

    関連する問題