开发者

How can I fill a page in Div in RoR?

开发者 https://www.devze.com 2022-12-15 17:35 出处:网络
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 ref

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:

  1. Use an iFrame to show the Google or Yahoo page
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消