5

$.getScriptGoogle マップ スクリプトを取得する関数で 2 つのスクリプトを読み込もうとしています。それが読み込まれた後、goMapマップ アプレットを簡単に作成できる別のスクリプト ( ) を取得します。

ただし、読み込まれると、Google Map API を取得する最初のスクリプトは適切ですが、2 番目のスクリプトは解析エラーを返し、次のように表示されます。

TypeError: 'undefined' はコンストラクターではありません'

それでも、それがどこから参照しているのか、どの行から参照しているのかはわかりません。このファイルでジオコーダーを実行しようとしているに違いないと思います(次の最初の行(function($){

http://www.pittss.lv/jquery/gomap/js/jquery.gomap-1.3.2.js

これが私のコードです:

$.getScript('http://maps.google.com/maps/api/js?sensor=true').done(function()
{
    $.getScript('../js/gomap.js').done(function()
    {
            // this never gets called
            alert('gomap loaded');
    }).fail(function(jqxhr, settings, exception)
    {
        alert(exception); // this gets shown
    });
}).fail(function()
{
    alert('failed to load google maps');
});

AJAX の設定を に変更してみましasyncfalseが、まったく役に立ちませんでした。

4

2 に答える 2

4

このエラーは、Google Maps API が<script src="http://maps.google.com/maps/api/js?sensor=true"></script>.

何らかの理由でそれができなくても、まだ希望はあります。document.writeページに依存関係を挿入するために使用されるため、Google Maps API は機能しません。document.writeコードを機能させるために、ネイティブメソッドを上書きできます。

デモ: http://jsfiddle.net/ZmtMr/

var doc_write = document.write; // Remember original method;
document.write = function(s) {$(s).appendTo('body')};
$.getScript('http://maps.google.com/maps/api/js?sensor=true').done(function() {
    $.getScript('../js/gomap.js').done(function() {
        alert('gomap loaded');
        document.write = doc_write; // Restore method
    }).fail(function(jqxhr, settings, exception) {
        alert(exception); // this gets shown
        document.write = doc_write; // Restore method
    });
}).fail(function() {
    alert('failed to load google maps');
});
于 2012-02-19T21:51:21.183 に答える
0

@lolwut試してみる

$.getScript('http://maps.google.com/maps/api/js?sensor=true').done(function()
{
    alert(11);
    $.getScript('http://www.pittss.lv/jquery/gomap/js/jquery.gomap-1.3.2.js').done(function()
    {
            // this never gets called
            alert('gomap loaded');
    }).fail(function(jqxhr, settings, exception)
    {
        alert(exception); // this gets shown
    });
}).fail(function()
{
    alert('failed to load google maps');
});

これが機能する場合は、相対パス../js/gomap.jsが間違っています!

于 2012-02-19T11:20:48.697 に答える