2016-03-26 14 views
-1

ここで私は何が間違っていますか?私は別のIDをクリックすると、 "ジャージー"のIDでdivに外部txtとhtmlをロードするようにしようとしています。私は何もクリックしていない今、同じままになります。AJAX?選択したIDのコンテキストを読み込まない

<html> 
<head> 
<meta charset="utf-8"> 
<title>Untitled Document</title> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script> 
<script type="text/javascript"> 


$(document).ready(function() { 
$("#test").click(function() { 
    $("#jersey").load("ajaxtest.txt"); 
}); 


$("#testtwo").click(function() { 
    $("#jersey").load("ajaxtesttwo.html"); 
}); 
}); 

</script> 


</head> 

<body> 

<a href="#" id="test">Test 1</a>||<a href="#" id="testtwo">Test 2</a> 
<div id="jersey">what a wonderful world</div> 
<br clear="all" /> 


</body> 
</html> 
+0

@Elvanos - 号 'load'があることないあなたのために – Quentin

+0

コードには明らかに間違ったことはありません。私はそれがうまくいかない理由を考えることができますが、あなたがブラウザにDeveloper Toolsを開いてConsoleを見れば明らかです。その非常に基本的なデバッグを済ませましたか? – Quentin

+0

ここにあなたの答えのリンクがありますこれをチェックしてください[http://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-support-for-http-error-when-loading-a-local]( http://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-support-for-http-error-when-loading-a-local) – Asad

答えて

-1

はかなり確信して、あなたはこのように、変数に外部ファイルの内容をロードし、アペンド機能のいくつかの種類を使用する必要があります。

$(document).ready(function() { 
$("#test").click(function() { 
    var temp_content = $.load("ajaxtest.txt"); 
    $("#jersey").html(temp_content); 
}); 


$("#testtwo").click(function() { 
    var temp_content = $.load("ajaxtesttwo.html"); 
    $("#jersey").html(temp_content); 
}); 
}); 
+0

いいえ「load」メソッドの全体点あなたのためにそれをするということです。確かに、同期HTTPリクエストは実行されず、結果が文字列として返されます。 – Quentin

+0

私は読書やYouTubeからこのすべてをやってきたことは分かりません。そのリンクのどこに私は何をすべきか教えていますか?すべてのファイルは同じフォルダにあります。私はなぜ彼らが接続するのか分からない。 – JCAthletics

関連する問題