Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8924707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:29:25+00:00 2026-06-15T07:29:25+00:00

I’m working in my development environment. The behavior I want: I have a form

  • 0

I’m working in my development environment. The behavior I want: I have a form on a modal dialog. The user clicks submit and data is sent to my “questions” controller. Some emails are sent and then the contents of the dialog are refreshed to say “Message sent successfully.” Pretty basic. The problem is that I can’t set the headers properly so rails is processing the data as html, not javascript. The emails go out but rails returns a 406 error. Here is my code:

_social.html.erb

    <div class='jqmWindow notices' id="emailModal">
      <h3>Email a link to this poll</h3>
      <p>You are emailing a link to the following poll:<br><strong><%=@question.text%></strong></p>
      <%= form_tag(:controller=>'questions', :action=>'email' , :method => "post",  :id=>"emailForm") do %>
              <%= label_tag(:emails_label, "Enter up to 20 email addresses separated by commas:" )%>
          <%= text_area_tag(:emails, "",:size => "60x6")%>
          <%= hidden_field_tag(:question_id, @question.id )%>
              <%= label_tag(:email_msg_label, "Enter a brief message to accompany your link:" )%>
          <%= text_area_tag(:email_msg, "",:size => "60x4")%><br>

          <%= submit_tag ( "Submit")%>
        <%end%>
    </div>

...

<script>

$(document).ready(function(){
  $('#shareModal').jqm();
  $('#emailModal').jqm();
  $.ajaxSetup({
    'beforeSend': function(xhr) {
        xhr.setRequestHeader("Accept", "text/javascript")
    }
  });


  $(document).ajaxSend(function(e, xhr, options) {
    var token = $("meta[name='csrf-token']").attr("content");
    xhr.setRequestHeader("X-CSRF-Token", token);
  });

...

  $('#emailForm').submit(function(){
    $.post($(this).attr('action'), $(this).serialize(), null, "script");
    return false;
  });
});

</script>

questions_controller.rb

 def email
    question = Question.find(params[:question_id])
    emails = params[:emails].split(/, /)
    emails.each do |recipient|
      GenericMailer.share(question, current_user.email, recipient, params[:email_msg]).deliver
    end
    respond_to do |format|
      format.js
    end


  end

email.js.erb (right now, this code never gets executed!)

alert("hello!");
$(#emailModal).html("Email sent successfully!");

and here are the headers:

    Request URL:http://127.0.0.1:3000/questions/emailForm/email?method=post
    Request Method:POST
    Status Code:406 Not Acceptable
    Request Headersview source
    Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
    Accept-Encoding:gzip,deflate,sdch
    Accept-Language:en-US,en;q=0.8
    Cache-Control:max-age=0
    Connection:keep-alive
    Content-Length:172
    Content-Type:application/x-www-form-urlencoded
__utma=96992031.1133215771.1353171766.1354190632.1354240040.26; __utmb=96992031.69.10.1354240040; __utmc=96992031; __utmz=96992031.1353379538.10.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=http://127.0.0.1:3000/questions/5
    Host:127.0.0.1:3000
    Origin:http://127.0.0.1:3000
    Referer:http://127.0.0.1:3000/questions/1
    User-Agent:Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11

Thanks in advance for any help you can provide!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:29:26+00:00Added an answer on June 15, 2026 at 7:29 am

    Thanks to all who responded. It turns out the ajax code was never even being executed. It was a rails problem. This was the culprit:

    <%= form_tag(:controller=>'questions', :action=>'email' , :method => "post",  :id=>"emailForm") do %>
    

    The id was being appended to the request, not added as a css idto the form tag. Thus the jQuery selector was not catching the form submission. The correct code:

    <%= form_tag({:controller=>'questions', :action=>'email' }, {:id=>"emailForm"}) do %>
    

    Cheers….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.