nMax = 15; // 最大値 nMin = 11; // 最小値 Math.floor(Math.random()*(nMax-nMin+1))+nMin;
//11~15がランダムで取得
意外と簡単。
ASでも使えますね。
$('ボタン').click(function(){
//送信したいformのアクションを取得(直接書いてもOK)
var actionURL=$('form').eq(0).attr("action")+"?";
//適当なパラメータ(ここではnameとageとしている)を追加
actionURL+="name="+$('input[class="name"]').val();
actionURL+="&age="+$('input[class="age"]').val();
$.post(actionURL, function(data){
//返り値がjsonの場合
var jsonObj = $.json.decode(data);//注意
if(jsonObj.status=="ok"){
//コールバックの処理
} }); })
こんな感じ
注意↓
下記ライブラリでjson→objectに変換
http://plugins2.jquery.com/project/LABSJSON