Amazon

2011年3月5日土曜日

Postのテスト用JavaScript

以下をHTMLのheadの下に追加。
<script type="text/javascript">
<!--

function submitForm(){
    var form = document.createElement('form');
    document.body.appendChild(form);
    var input = document.createElement('input');
    input.setAttribute( 'type' , 'hidden');
    input.setAttribute( 'name' , 'name' );
    input.setAttribute( 'value' , 'Nanashi' );
    form.appendChild( input ); 
var input = document.createElement('input');
 var array = ["f0001","f0002","f0003"];
    input.setAttribute( 'type' , 'hidden');
    input.setAttribute( 'name' , 'array' );
    input.setAttribute( 'value' , array ); 
var input = document.createElement('input');
 var listArray = [{key11:"value1",key12:"value2"},{key21:"value21",key22:"value22"}];
    input.setAttribute( 'type' , 'hidden');
    input.setAttribute( 'name' , 'listArray' );
    input.setAttribute( 'value' , listArray );
    form.appendChild( input );
 var input = document.createElement('input'); 
 //配列の配列
var arrayArray = [["p1","p2","p3"],["p3","p5","p1"]];
    input.setAttribute( 'type' , 'hidden');
    input.setAttribute( 'name' , 'arrayArray' );
    input.setAttribute( 'value' , arrayArray );
    form.appendChild( input ); 
// 以下のPOST先は適宜変更
form.setAttribute( 'action' , 'http://localhost:8080/request/post');
    form.setAttribute( 'method' , 'post' );
    form.submit();
}

</script> 
        <body>
      
   
<input type="button" value="doPost" onClick="JavaScript:submitForm()" />
<a href=“JavaScript:submitForm()”>クリックしたら値POST送信</a>


        </body>
      
</html>

0 件のコメント:

コメントを投稿

Amazon3