I'm using the jQuery Form Plugin on a big ass form which includes some file fields. The back end is Ruby on Rails.
I'm having trouble getting Rails to recognize the POST request type to be 'text/javascript' even though I believe I am setting it correctly.
The form looks like:
<form id="listing_form" method="POST" enctype="multipart/form-data" action="/listings">
<input type="text" size="30" name="listing[venue][phone]" id="listing_venue_phone"/>
<input type="file" size="30" name="listing[venue][image]" id="listing_venue_image"/>
...plus tons of other fields
The js looks like:
$("#listing_form").ajaxForm({ dataType: 'script' });
And I also have declared:
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader('Accept', 'text/javascript')}
});
The request makes it to the controller, but the Rails respond_to block sees it as a normal html request. Also, Firebug shows a parser error and fails to display the request and response headers in the console.
If I remove the file field and POST the text fields only, the respond_to block handles the request as a js request and properly executes the create.js.erb file.
How can I get Rails to properly respond to the request? Thanks.