0
私が必要とするデータは、ウィキペディアのes(スペイン語版)でのみ利用可能で、これは私のスクリプトを壊しています。私はまだだけでなく、英語のデータを必要とするしかし、JSの私の知識は非常に最小限であるURLを、どのように私は両方のAPIから取得するために、これを変換することができます wikipediaから複数のURL(言語)のデータを提供する方法
それは https://en.wikipedia.org/w/api.phpから呼び出しますが、この特定のデータは https://es.wikipedia.org/w/api.phpでしか入手できない参照お返事ありがとうございます。
$.ajax({
url: 'https://en.wikipedia.org/w/api.php',
data: {
format: 'json',
action: 'parse',
page: this_target,
prop:'text',
section:0,
},
dataType: 'jsonp',
success: function (data) {
//console.log(data)
$(id_target).find('.o-modal__inner').html('');
$(id_target).find('.o-modal__title').html('').hide();
$(id_target).find('.o-modal').addClass('isOpen');
if(!$(id_target).find('.a-more').hasClass('isActive')){
$(id_target).find('.a-more').trigger('click');
}
var markup = data.parse.text['*'];
var i = $('<div></div>').html(markup);
i.find('a').each(function() { $(this).replaceWith($(this).html()); });
i.find('sup').remove();
i.find('.mw-ext-cite-error').remove();
setTimeout(function() {
$(id_target).find('.o-modal__title').html(data.parse.title).fadeIn(300);
$(id_target).find('.o-modal__inner').html($(i).find('p'));
$(id_target).find('.a-loader').hide();
}, 1000);
}
});
});
:)私はこれらの間にコードを挿入するようにしています私にフランス語を話します私は本当にJSについて知っています。ちょうどこのちょっとしたおしゃべりまで追跡しました.... dataType: 'jsonp'、if(data.error &&新しいURL(this.url).hostname === "en.wikipedia。 org "){ this.url = this.url.replace( 'en'、 'es') $ .ajax(this); リターン; } 成功:関数(データ){ – user3677211
いいえ、成功コールバックの中で、その先頭に設定する必要があります: 'success:function(data){if(data.error && new URL(this.url).hostname === "en.wikipedia.org"){...} ...}、 '。ところで、私は両方のウィキのために表示するものは何もないケースを処理する答えを更新 –
ありがとう、完璧に働いた – user3677211