Rails 5.2.1 UJS: javascript response is rendering text instead of being executed











up vote
0
down vote

favorite












I've looked at many of the other answers to this question, and none work for me.



Given this form:



<form data-remote="true" method="POST" accept-charset="UTF-8" action="/admin/audiences/search/industry.js">
<div class="form-group">
<input data-target="lookup.value" type="text" class="form-control" id="q" name="q" placeholder="Start typing to search...">
</div>
</form>


Pressing return after typing in the field gives this error in the console: Resource interpreted as Document but transferred with MIME type text/javascript, and the correct javascript is rendered as text in the browser, rather than being executed as something with data-remote='true' is expected to be.



The server response is:



Started POST "/admin/audiences/search/industry.js" for 127.0.0.1 at 2018-11-19 10:29:04 -0500
Processing by Admin::AudiencesController#search as JS
Parameters: {"q"=>"a", "type"=>"industry"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ /Users/timsullivan/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
(36.6ms) SELECT DISTINCT "salesforce"."account"."industry" FROM "salesforce"."account" WHERE (industry ilike '%a%')
↳ app/controllers/admin/audiences_controller.rb:89
Rendering admin/audiences/search.js.erb
Rendered admin/audiences/search.js.erb (0.5ms)
Completed 200 OK in 90ms (Views: 12.4ms | ActiveRecord: 37.1ms)


Note that the server properly recognizes that it's a JS request, and is returning a JS response, and even the browser is recognizing that it's getting JS, it's just rendering it as a document.



Other UJS elements on the page work fine, it's just this one, so rails_ujs is working properly, at least sometimes. The worst part is that this USED to work before I made some changes, and undoing those changes hasn't fixed the problem.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I've looked at many of the other answers to this question, and none work for me.



    Given this form:



    <form data-remote="true" method="POST" accept-charset="UTF-8" action="/admin/audiences/search/industry.js">
    <div class="form-group">
    <input data-target="lookup.value" type="text" class="form-control" id="q" name="q" placeholder="Start typing to search...">
    </div>
    </form>


    Pressing return after typing in the field gives this error in the console: Resource interpreted as Document but transferred with MIME type text/javascript, and the correct javascript is rendered as text in the browser, rather than being executed as something with data-remote='true' is expected to be.



    The server response is:



    Started POST "/admin/audiences/search/industry.js" for 127.0.0.1 at 2018-11-19 10:29:04 -0500
    Processing by Admin::AudiencesController#search as JS
    Parameters: {"q"=>"a", "type"=>"industry"}
    User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
    ↳ /Users/timsullivan/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
    (36.6ms) SELECT DISTINCT "salesforce"."account"."industry" FROM "salesforce"."account" WHERE (industry ilike '%a%')
    ↳ app/controllers/admin/audiences_controller.rb:89
    Rendering admin/audiences/search.js.erb
    Rendered admin/audiences/search.js.erb (0.5ms)
    Completed 200 OK in 90ms (Views: 12.4ms | ActiveRecord: 37.1ms)


    Note that the server properly recognizes that it's a JS request, and is returning a JS response, and even the browser is recognizing that it's getting JS, it's just rendering it as a document.



    Other UJS elements on the page work fine, it's just this one, so rails_ujs is working properly, at least sometimes. The worst part is that this USED to work before I made some changes, and undoing those changes hasn't fixed the problem.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I've looked at many of the other answers to this question, and none work for me.



      Given this form:



      <form data-remote="true" method="POST" accept-charset="UTF-8" action="/admin/audiences/search/industry.js">
      <div class="form-group">
      <input data-target="lookup.value" type="text" class="form-control" id="q" name="q" placeholder="Start typing to search...">
      </div>
      </form>


      Pressing return after typing in the field gives this error in the console: Resource interpreted as Document but transferred with MIME type text/javascript, and the correct javascript is rendered as text in the browser, rather than being executed as something with data-remote='true' is expected to be.



      The server response is:



      Started POST "/admin/audiences/search/industry.js" for 127.0.0.1 at 2018-11-19 10:29:04 -0500
      Processing by Admin::AudiencesController#search as JS
      Parameters: {"q"=>"a", "type"=>"industry"}
      User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
      ↳ /Users/timsullivan/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
      (36.6ms) SELECT DISTINCT "salesforce"."account"."industry" FROM "salesforce"."account" WHERE (industry ilike '%a%')
      ↳ app/controllers/admin/audiences_controller.rb:89
      Rendering admin/audiences/search.js.erb
      Rendered admin/audiences/search.js.erb (0.5ms)
      Completed 200 OK in 90ms (Views: 12.4ms | ActiveRecord: 37.1ms)


      Note that the server properly recognizes that it's a JS request, and is returning a JS response, and even the browser is recognizing that it's getting JS, it's just rendering it as a document.



      Other UJS elements on the page work fine, it's just this one, so rails_ujs is working properly, at least sometimes. The worst part is that this USED to work before I made some changes, and undoing those changes hasn't fixed the problem.










      share|improve this question













      I've looked at many of the other answers to this question, and none work for me.



      Given this form:



      <form data-remote="true" method="POST" accept-charset="UTF-8" action="/admin/audiences/search/industry.js">
      <div class="form-group">
      <input data-target="lookup.value" type="text" class="form-control" id="q" name="q" placeholder="Start typing to search...">
      </div>
      </form>


      Pressing return after typing in the field gives this error in the console: Resource interpreted as Document but transferred with MIME type text/javascript, and the correct javascript is rendered as text in the browser, rather than being executed as something with data-remote='true' is expected to be.



      The server response is:



      Started POST "/admin/audiences/search/industry.js" for 127.0.0.1 at 2018-11-19 10:29:04 -0500
      Processing by Admin::AudiencesController#search as JS
      Parameters: {"q"=>"a", "type"=>"industry"}
      User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
      ↳ /Users/timsullivan/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
      (36.6ms) SELECT DISTINCT "salesforce"."account"."industry" FROM "salesforce"."account" WHERE (industry ilike '%a%')
      ↳ app/controllers/admin/audiences_controller.rb:89
      Rendering admin/audiences/search.js.erb
      Rendered admin/audiences/search.js.erb (0.5ms)
      Completed 200 OK in 90ms (Views: 12.4ms | ActiveRecord: 37.1ms)


      Note that the server properly recognizes that it's a JS request, and is returning a JS response, and even the browser is recognizing that it's getting JS, it's just rendering it as a document.



      Other UJS elements on the page work fine, it's just this one, so rails_ujs is working properly, at least sometimes. The worst part is that this USED to work before I made some changes, and undoing those changes hasn't fixed the problem.







      javascript ruby-on-rails






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 at 16:00









      Tim Sullivan

      13.2k1169111




      13.2k1169111
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          As with so many of my problems, recently, this one is embarrassing:



          Nested HTML forms: you can't have them.



          I mean, I knew this, but the form from the question is inserted dynamically into the page, and it happens to fall within a form in this case. So, it's not getting properly hooked by the UJS stuff, and sends the request without AJAX at all.



          On the upside, I now know more about how UJS works than any mortal should.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378433%2frails-5-2-1-ujs-javascript-response-is-rendering-text-instead-of-being-executed%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            As with so many of my problems, recently, this one is embarrassing:



            Nested HTML forms: you can't have them.



            I mean, I knew this, but the form from the question is inserted dynamically into the page, and it happens to fall within a form in this case. So, it's not getting properly hooked by the UJS stuff, and sends the request without AJAX at all.



            On the upside, I now know more about how UJS works than any mortal should.






            share|improve this answer

























              up vote
              0
              down vote













              As with so many of my problems, recently, this one is embarrassing:



              Nested HTML forms: you can't have them.



              I mean, I knew this, but the form from the question is inserted dynamically into the page, and it happens to fall within a form in this case. So, it's not getting properly hooked by the UJS stuff, and sends the request without AJAX at all.



              On the upside, I now know more about how UJS works than any mortal should.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                As with so many of my problems, recently, this one is embarrassing:



                Nested HTML forms: you can't have them.



                I mean, I knew this, but the form from the question is inserted dynamically into the page, and it happens to fall within a form in this case. So, it's not getting properly hooked by the UJS stuff, and sends the request without AJAX at all.



                On the upside, I now know more about how UJS works than any mortal should.






                share|improve this answer












                As with so many of my problems, recently, this one is embarrassing:



                Nested HTML forms: you can't have them.



                I mean, I knew this, but the form from the question is inserted dynamically into the page, and it happens to fall within a form in this case. So, it's not getting properly hooked by the UJS stuff, and sends the request without AJAX at all.



                On the upside, I now know more about how UJS works than any mortal should.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 19:11









                Tim Sullivan

                13.2k1169111




                13.2k1169111






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378433%2frails-5-2-1-ujs-javascript-response-is-rendering-text-instead-of-being-executed%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen