Why do I need to add "data: {type:" script "}" via a remote link with rails / ajax

in my one project, code:

  = link_to "add", new_me_category_path, class: "btn btn-success", remote: true

can correctly load the remote form.

But someone cannot work, the browser did not execute responese js code. I need to add "data: {type:" script "}" as follows:

  = link_to "add", new_me_category_path, class: "btn btn-success", remote: true, data: {type: "script"}

I want to know the reason.

+5
source share
3 answers

I am not a JS expert, and I do not know Ruby, but I think:

If the data type is set to script- loaded and downloaded downloaded code immediately.

When the default data type is ( html), the downloaded code is simply loaded into the browser. You must execute it "manually" (for example, by calling some function).

- ( html).

- , , .

, jQuery.get() jQuery.getScript().

+4

jQuery ajax: http://api.jquery.com/jquery.ajax/ uJS https://github.com/rails/jquery-ujs, data-remote="true" , remote: true.

, Ajax HTTP Accepts dataType accepts, ajax(), data- uJS.

dataType data-type, jQuery "". , .

+2

script .ejs ( raw script : render js: 'some code'). html j ejs :

template.ejs

$('some selector').html('<%= j render('some template') %>');

, url. .js.

+1

All Articles