私は一般的にjqueryとコーディングが初めてです。これは私がやろうとしていることです:
- リンクをクリックすると、 #country_slide div が展開されます
- 「読み込み中」のテキストを表示
- ajaxが成功したらhtmlファイルの内容をdivに入れる
- それ以外の場合は、エラーを警告して div を閉じます
これは私が今持っているコードです:
http://jsfiddle.net/spadez/n9nVs/5/
window.onload = function () {
var a = document.getElementById("country_link");
a.onclick = function () {
$.ajax({
type: 'GET',
dataType: 'html',
url: '/ajax/test.html',
timeout: 5000,
beforeSend : function() {
$("#country_slide").show();
$("#country_slide").val('<p>Loading</p>')
},
success: function (data, textStatus) {
$("#country_slide").html(data);
alert('request successful');
},
error: function (xhr, textStatus, errorThrown) {
alert('request failed');
$("#country_slide").hide();
},
complete : function() {
$('.loader').hide();
},
});
return false;
}
}
リンクをクリックしても、ボックスに読み込み中のテキストが表示されません。ここでどこが間違っているのか誰か教えてください。また、私の最初の jquery スクリプトについて何かアドバイスをいただける方がいらっしゃいましたら、よろしくお願いいたします。