2014-11-08 17 views
0

我有一个很大的烦恼,我无法弄清楚。 我的Rails应用程序发布了一个jQuery post请求,它在开发过程中非常好用,但却变成了Get in production。 资产似乎正确预编译,实际上,我可以美化生产JS代码,并找到确切的Ajax代码(同样的代码,我在发展..)jQuery Ajax发展中获取生产

//my js 
$(document).on("click", ".create-candidate-submit", function (e, data) { 
urlToPost = DOMAIN_NAME + "stories/" + e.currentTarget.id + "/" + "candidates/"; 
console.log("urlToPost", urlToPost); 
$.ajax({ 
    type: "POST", 
    url: urlToPost, 
    data: {"candidate": { 
     "text": $("#createNewCandidate").val(), 
     "story_id": e.currentTarget.id 
    } 
    }, 
    dataType: "script", 
    success: function (res) { 
     console.log("success called..", res); 
     // eval(res); 
    } 
}); 

});

//erb 
    <%= form_for [@story,@candidate],remote: true, html: {:role=>"form"} do |f|%> 
      <div class="form-group"> 
      <label for="createNewCandidate">create story</label> 
      <%=f.text_field :text,{:class=>"form-control",:id=>"createNewCandidate",:size=>30}%> 
      <%=f.hidden_field :story_id%> 
      <%=f.hidden_field :user_id %> 
      <div class="btn btn-primary create-candidate-submit" id="<%[email protected]%>">שלח</div> 

      </div> 
     <%end%> 

applicaiton.js.erb 
//= require jquery 
//= require jquery_ujs 
//= require twitter/bootstrap 
//= require turbolinks 
//= require css_settings.js.erb 
//= require_tree . 

生产中出现了一些问题,我不能为我的生活找出答案。请帮助!

回答

0

你可以试试$ .post而不是$ .ajax?

0

应该有更多的仔细阅读jQuery的文档(这有什么好使用Rails做)

“脚本”:评估响应为JavaScript,并返回纯文本。除非缓存选项设置为true,否则通过向URL追加查询字符串参数“_ = [TIMESTAMP]”来禁用缓存。注意:这会将POST转换为远程域请求的GET。

我确定这是什么原因导致我的问题。