开发者

does $.getJSON can receiver default url value?

开发者 https://www.devze.com 2023-01-20 21:58 出处:网络
I use rails with jQuery. a scenario like that def method_1 respond_to |format| format.html {} format.json {return the calculate value}

I use rails with jQuery. a scenario like that

def method_1
 respond_to |format|
 format.html {}
 format.json {return the calculate value}
end

the method recieve a couple of different params, and calculate different value. so when user browser method_1/1 and jQuery code in method_1 view can receive the format.json value, when user browse开发者_如何学运维r method_1/2 and jQuery code in method_1 view can receive the format.json value.

how to?


Looks to me like '1' and '2' are just IDs of some object. If that's the case, this is a simple matter of:

@object = ObjectClassName.find(params[:id])
respond_to do |format|
  format.html
  format.js { render :json => @object }
end

If the params are not object IDs then you have to clarify what you mean.

0

精彩评论

暂无评论...
验证码 换一张
取 消