I have a div called "main", and I have two hyper link, one is called "Google", another is "Yahoo!" , I want the user click the "Google", and the google.com will fill in the main div within refresh, same as "Yahoo!". what should I开发者_运维问答 do in RoR?
You cannot load the content of google or yahoo directly to a div via AJAX as the browser security model prevents XmlHttpRequests to other domains, so you basically have 2 options:
- Use an iFrame to show the Google or Yahoo page
- Load the requested page on the server and populate the div with the loaded html.
Since for 1.) you don't need any server side code, I guess you are looking for a way to do 2.) in RoR. You can use the httpclient library for that, but be aware that including foreign html in your page is a mess and will probably not work as expected without great effort.
If you are just trying to show google search results in you app, you should have a look at their api.
This does not need any Rails intervention. Take a look at these:
http://docs.jquery.com/Ajax
http://api.prototypejs.org/ajax/ajax.html
and choose your poison.
精彩评论