非同期通信を行う

書式

$.ajax(prop)

prop : 通信パラメータ(ハッシュ形式で指定)

説明

非同期通信を行うには$.ajax()を使います。パラメータはハッシュ(連想配列)形式で指定します。以下の属性を指定できます。

urlURL
type通信方法(get, post等)
dataTypeデータタイプ
ifModified変更時のみ読み込むかどうかのフラグ
timeoutタイムアウト秒数
globalフラグ
success成功時の処理
errorエラー時の処理
complete通信完了時の処理
data送信データ
contentTypeMIME形式
processData
async非同期通信フラグ
beforeSend送信前処理(カスタムヘッダー等の処理)

サンプルコード [実行]

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="main.css" type="text/css" media="all">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript"><!--
$(document).ready(function (){
result = $.ajax( {
type : "get",
url : "./sample.html",
dataType : "html",
success : function(data){
alert(data);
}
});
});
// --></script>
</head>
<body>
<h1>非同期通信でデータを読み込む</h1>
</body>
</html>