jquery - problem in remote ajax request -


excuse me,i using rails 2.3.8 . have remote form in popup. use javascript code submit post because need post in multipart. ok?

the partial of form in popup is:

<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 contain url of uploaded image.                     // put in image element create, or will.                     // example, if have image elemtn id "my_image",                     //  $('#my_image').attr('src', xmlhttprequest.responsetext);                     // set image tag display 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} |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 |builder| %>           <% f.fields_for :product_images, 4.times { productimage.new } |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> 

my controller

  def create_starred_product     product = product.new(params[:product])     if product.valid? && product.save       render :update |page|         #puts in page name of product         page.replace_html 'star-product', :partial => "admin/products/star_product_name", :locals => {:star_product => product}         #close popup. use $j conflict between jquery , prototype         page.call "$j.modal.close"       end     else     end   end 

however when finished action have error in console of firebug:

s.error.call(s.context, xhr, 'error', e);

so render :update don´t update page.

note: save product properly.

why error occurs?

thank in advance

in controller add

respond_to |format|   format.js { render :json => product } end 

then add code in jquery according functionality inside

      complete: function(xmlhttprequest, textstatus) {                         // xmlhttprequest.responsetext contain url of uploaded image.                         // put in image element create, or will.                         // example, if have image elemtn id "my_image",                         //  $('#my_image').attr('src', xmlhttprequest.responsetext);                         // set image tag display uploaded image.                         //here add code update page example                         //parsejson data                           var product = $j.parsejson(xmlhttprequest.responsetext);                         //add info in page in rails 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 modal                     $j.modal.close();                     } 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -