页面提交一个购物链接,服务器端获取商品信息返回页面 V 端代码 1
<%= form_for @product, html: {class: 'form-vertical'}, remote: true do |f| %>
<fieldset>
<div class="form-group">
<div class="col-xs-10 col-sm-10">
<%= f.text_field :buy_link, class: "form-control", placeholder: "http://item.taobao.com/item.htm?id=42249333320" %>
</div>
<div class="col-xs-2 col-sm-2">
<%= f.submit "确认采集", class: 'btn btn-primary', data: {disable_with: "正在采集..."} %>
</div>
</div>
</fieldset>
<% end %>
C 端代码 1
good = TaoBaoApi::Good.new params[:product][:buy_link]
item = good.get_info
respond_to do |format|
format.json { render :text => { :find => "NO",:data =>item}.to_json }
end
js 代码
$(document).ready(function () {
$("#new_product").on("ajax:success", function (xhr, data, status) {
。。。。。。。。。。。。。。。。。。。
这个是正常的,我想讲 v 端和 c 端修改一下成为 2,结果 js 获取不到数据了 V 端代码 2
<form class="form-horizontal" id="new_product1" method="post" data-remote="true" accept-charset="UTF-8" action="/products/getgood/">
<fieldset>
<div class="form-group">
<div class="col-xs-8 col-sm-8">
<input class="form-control" id="buy_link" name="buy_link" placeholder="copy item link" type="url" />
</div>
<div class="col-xs-4 col-sm-4">
<button class="btn btn-primary" type="submit"><i class="fa fa-plus fa-lg"></i> 载入</button>
</div>
</div>
</fieldset>
</form>
C 端代码 2
def getgood
good = TaoBaoApi::Good.new params[:buy_link]
item = good.get_info
render :text => { :find => "NO",:data =>item}.to_json
end