0
我想將ajax請求的結果發回到它所請求的同一頁面。下面是相互作用的部分:使用ajax回發到同一頁
AJAX jQuery中
var ids = 1
$(document).ready(function(){
$('#showbtn').on('click', function() {
$.ajax({
url: "http://localhost:3000/teamplayers.json",
data: {'resolution':ids},
type:"post",
dataType: "json",
cache: true,
success:function(){
$('#test3').val(1);
alert("test 3");
},
error: function(error) {
alert("Failed " + console.log(error) + " " + error)
}
});
});
});
這應該是在這裏設置變量: Teamplayer控制器
# GET /teamplayers
# GET /teamplayers.json
def index
@teamplayers = Teamplayer.all
@fteams = Fteam.all
@teamplayer2 = 1
tid = params[:resolution] <-It should set here per the data section above
@ids = tid
end
不幸的是它調用的這一部分相同的控制器
# POST /teamplayers
# POST /teamplayers.json
def create
@teamplayer = Teamplayer.new(teamplayer_params)
respond_to do |format|
if @teamplayer.save
format.html { redirect_to @teamplayer, notice: 'Teamplayer was successfully created.' }
format.json { render action: 'show', status: :created, location: @teamplayer }
else
format.html { render action: 'new' }
format.json { render json: @teamplayer.errors, status: :unprocessable_entity }
end
end
end
那麼我該怎麼做才能發佈到同一頁面。
但是當我做的GET,它在頁面的結束通話與數據頁。我想要這個:http:// localhost:3000/teamplayers /而不是:http:// localhost:3000/teamplayers/1 – user3240928
@ user3240928更新的答案反映了這一點,但是您需要傳遞'resolution'作爲查詢字符串論據。 – mellowfish
好吧,現在我知道它正在傳遞值,但是如何將值作爲整數 – user3240928