- 登録者: justoneplanet
- 最終更新日時: 2008/12/02 23:36
- 部屋の種別: 大部屋
- 参加人数: 3
- トピック数: 1
- アクセス数: 660
- タグ: javascript
JavaScriptのお部屋です。皆様どうぞよろしくおねがいいたします。
トピック
並び替え: 更新日順 | 新着順 | アクセス数順 | コメント数順
- クロスドメインAjaxのサンプル
- by:justoneplanet
- 更新日:2008/12/02
■test.html
同じディレクトリにおいてテストしてください。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script type="text/javascript" id="cb">
</script>
<script type="text/javascript">
function callback(txt){
alert(txt);
}
window.onload = function(){
document.getElementById('button').onclick = function(){
var originalScriptNode = document.getElementById('cb');
var newScriptNode = document.createElement('script');
var query = document.getElementById('text').value;
newScriptNode.id = 'cb';
newScriptNode.charset = 'utf-8';
newScriptNode.src = 'test.php?query=' + query;
originalScriptNode.parentNode.replaceChild(newScriptNode, originalScriptNode);
}
}
</script>
</head>
<body>
<form action="#" method="get">
<input type="text" name="text" id="text" size="10" />
<input type="button" name="button" id="button" value="submit" />
</form>
</body>
</html>
■test.php
<?php
print('callback("' . $_GET['query'] . '");');
?>
■一言
同じディレクトリにおいてテストしてください。
- アクセス数:245件
- コメント数:1件
前へ 1 次へ![]()





