Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 远程ajax请求中的问题_Jquery_Ruby On Rails_Ajax - Fatal编程技术网

Jquery 远程ajax请求中的问题

Jquery 远程ajax请求中的问题,jquery,ruby-on-rails,ajax,Jquery,Ruby On Rails,Ajax,对不起,我使用的是rails 2.3.8。 我在弹出窗口中有一个远程窗体。这使用了一个javascript代码来提交帖子,因为我需要多部分的帖子。好吗 弹出窗口中的部分表单为: <script type="text/javascript"> $j(document).ready(function() { $j('#product_submit').click(function(event) { event.preventDefault(

对不起,我使用的是rails 2.3.8。 我在弹出窗口中有一个远程窗体。这使用了一个javascript代码来提交帖子,因为我需要多部分的帖子。好吗

弹出窗口中的部分表单为:

<script type="text/javascript">
    $j(document).ready(function() {
        $j('#product_submit').click(function(event) {
            event.preventDefault();
            $j('#uploadForm').ajaxSubmit({
                beforeSubmit: function(a, f, o) {
                    o.dataType = 'json';
                },
                complete: function(XMLHttpRequest, textStatus) {
                    // XMLHttpRequest.responseText will contain the URL of the uploaded image.
                    // Put it in an image element you create, or do with it what you will.
                    // For example, if you have an image elemtn with id "my_image", then
                    //  $('#my_image').attr('src', XMLHttpRequest.responseText);
                    // Will set that image tag to display the uploaded image.
                }
            });
        });
    });
</script>
<div id="new-starred-product" class="popup clearfix">
  <div class="header">Nuevo producto estrella</div>
  <div id="messages">

  </div>
  <% remote_form_for @product, :url => {:controller => "products", :action => "create_starred_product"}, :html => {:method => :post, :id => 'uploadForm', :multipart => true} do |f| %>
      <div class="content">
        <label>Nombre:</label> <%= f.text_field :name, :class => "textarea" %>
        <br/>
        <label>Precio:</label> <%= f.text_field :price, :class => "textarea" %>
        <br/>
        <%#= f.file_field :photo %>
        <div class="images-selector">

          <% count = 0 %>
          <%# f.fields_for "product_images_attributes[]", ProductImage.new do |builder| %>
          <% f.fields_for :product_images, 4.times { ProductImage.new } do |builder| %>
              <% if builder.object.new_record? %>
                  <label>
                    Imagen <%= "#{count = count + 1}" %>
                  </label>
                  <%= builder.file_field :photo, :class => "file-upload" -%>
                  <br/>
                  <br/>
              <% end %>
              <%#= builder.text_field :testfield %>
              <!--ACA VA EL CODIGO PARA IMAGENES-->
          <% end %>
        </div>
        <br/>
        <label>Descripción</label><%= f.text_area :description, :rows => 10, :class => "textarea clearfix" -%>
        <br/>

        <p>
          <%#= f.submit "Crear" %>
          <%= link_to "Crear", "#", :id => "product_submit" %>
        </p>
      </div>
  <% end %>
</div>
但是,当完成操作时,firebug控制台中出现以下错误:

s、 调用(s.context,xhr,'error',e)

所以呈现:更新不更新我的页面

注意:我正确保存了产品

为什么会发生这种错误

在控制器添加中提前感谢

respond_to do |format|
  format.js { render :json => product }
end
然后根据jQuery中的功能在jQuery中添加代码

      complete: function(XMLHttpRequest, textStatus) {
                        // XMLHttpRequest.responseText will contain the URL of the uploaded image.
                        // Put it in an image element you create, or do with it what you will.
                        // For example, if you have an image elemtn with id "my_image", then
                        //  $('#my_image').attr('src', XMLHttpRequest.responseText);
                        // Will set that image tag to display the uploaded image.
                        //HERE ADD YOUR CODE FOR UPDATE PAGE EXAMPLE
                        //parseJson my data  
                        var product = $j.parseJSON(XMLHttpRequest.responseText);
                        //add info in page in rails is render :update
                    $j("#star-product").html("<input type='hidden' id='star-product-id' value='" + product.product.id.toString() + "' name='star-product'/>");
                    $j("#star-product").append("<span id='star-product-name-span'>"+ product.product.name.toString() + "</span>");
                    //close the modal
                    $j.modal.close();
                    }
complete:函数(XMLHttpRequest,textStatus){
//XMLHttpRequest.responseText将包含上载图像的URL。
//将其放入您创建的图像元素中,或按您的意愿使用它。
//例如,如果您有一个id为“my_image”的图像元素,则
//$('my#u image').attr('src',XMLHttpRequest.responseText);
//将设置该图像标记以显示上载的图像。
//这里添加更新页面示例的代码
//解析我的数据
var product=$j.parseJSON(XMLHttpRequest.responseText);
//在rails的页面中添加信息呈现:更新
$j(“#星产品”).html(”);
$j(“#星型产品”).append(“+product.product.name.toString()+”);
//关闭模式
$j.modal.close();
}
      complete: function(XMLHttpRequest, textStatus) {
                        // XMLHttpRequest.responseText will contain the URL of the uploaded image.
                        // Put it in an image element you create, or do with it what you will.
                        // For example, if you have an image elemtn with id "my_image", then
                        //  $('#my_image').attr('src', XMLHttpRequest.responseText);
                        // Will set that image tag to display the uploaded image.
                        //HERE ADD YOUR CODE FOR UPDATE PAGE EXAMPLE
                        //parseJson my data  
                        var product = $j.parseJSON(XMLHttpRequest.responseText);
                        //add info in page in rails is render :update
                    $j("#star-product").html("<input type='hidden' id='star-product-id' value='" + product.product.id.toString() + "' name='star-product'/>");
                    $j("#star-product").append("<span id='star-product-name-span'>"+ product.product.name.toString() + "</span>");
                    //close the modal
                    $j.modal.close();
                    }