javascript - Difference between simple ajax and :remote => true In Ruby on Rails -
actually have two, 3 questions heart of 3 question same written in title . make points clear here in description
following specification of question
javascript file path => assets/javascript/ js.erb file path => views/customers/index.js.erb view file name => views/customers/html.erb controller name => customers action name => index
point # 1
if make ajax call customers/index through javascript file (with mentioned path) hit index.js.erb file ?
point # 2
can use js , js.erb file same action . mean 'is possible send ajax js file in assets folder , after controller action index method handle response in index.js.erb file in view folder ?'
point # 3
say can handle response in index.js.erb file how can / or if can stop sending response / data in js file
if have missed more related points kindly edit question , place , maximum people can enjoy knowledge
also have @ this question , answer if can
update
i made small experiment , keeping same function mentioned in 1: linked question , if ajax sent through js file js.erb doesn't thing if made ajax call using :remote => true
, hits js.erb file . explaination appreciated . having @ code sample in js, controller , js.erb kindly see linked question
i think language barrier making hard understand question i'll try answer.
the flow in rails :remote => true
this:
click on :remote => true link (foo
) -> ajax call made controller requesting execute foo
-> controller executes code contained in foo
action, file in same view's folder called foo.js.erb
, execute js -> code update portion of original html page using file called foo.html.erb
in same view's folder.
any call js function contained in assets/javascript/
execute js called, whether ajax or not.
so assets/javascript/
= place put js code instead of putting in <script>
tags in html file
:remote => true
= ajax call specific controller action renders named .js.erb file , .html.erb file update page asynchronously.
Comments
Post a Comment