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 8879203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:53:58+00:00 2026-06-14T19:53:58+00:00

Consider the following form in .erb view: <%= form_tag(harvester_next_url, :method => post, :remote =>

  • 0

Consider the following form in .erb view:

<%= form_tag(harvester_next_url, :method => "post", :remote => true, "data-type" => :json, :id => "answerForm") do %>
<div id="dynamicFormContent"></div>
<% end %>

In certain circumstances, I want to issue a JS callback in the next method with
render :js => "window.location = '#{definitions_path}'"

However, this does not execute in browser. The response has “window.location…” in body and the content-type is set to text/javascript, the request’s accept has text/javascript, too.

The Rails version is 3.2.8.

Some additional information: I don’t want to switch form action to use JS format as JS callback code is only one of the possible responses from the controller. The other time, I need some JSON from it to deal with.

The question: is there a possibility to make it work without using client-side redirection (i.e. getting window.location from JSON response), etc.? AFAIK, this works OK for non-remote forms.

ADD It ends up with status = "parsererror" when XHR completes. Clearly, this is because jQuery attempts to parse response as JSON, even though it’s text/javascript. The question is still open.

  • 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-14T19:54:00+00:00Added an answer on June 14, 2026 at 7:54 pm

    Finally I’ve got it working. However, I’ve realized that it is generally a dirty approach (you all told me so) to execute incoming JS as-is. But, as long as my question was about that dirty approach, I’ll post an idea of how to make it work if you really need it.

    Given that we have parsererror status in case we supply plain JS, we can:

    $('#answerForm').on('ajax:error',
      function(e, data, status, xhr)
      {
        $.globalEval(data.responseText);
      }
    );
    

    Thanks everyone!

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

Sidebar

Related Questions

Consider the following form: <form action="/a" method="post"> <input name="x" type="text" onblur="myonblur(e)" /> <input name="y"
Please consider the following code, <form action=index.php method=post name=adminForm enctype=multipart/form-data> <input type=hidden name=showtime[] id=showtime_1
Consider the following Mechanize form object #<Mechanize::Form {name f1} {method POST} {action f.php} {fields
Consider the following form containing textfield and submit button: <form method=POST action=<?php isValid();?> class=urln>
Consider the following JSF (& jQuery Mobile) markup: <h:form> <a href=#login data-rel=popup>Please login</a> <h:outputText
Based on: MVC Html.CheckBox and form submit issue Let's consider following example. View: <%
Please consider the following signup: <form wicket:id=form> <div wicket:id=fooList> <input wicket:id=fooList.quxField type=text size=10/> </div>
Consider the following code; it's basically a form that sends some data via HTTP
Please consider the following non-working HTML document: <html> <body> <form action= method=GET onsubmit=return f(this);>
Consider the following form: I want textbox1 or textbox2 to be focused when i

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.