views:

81

answers:

2

I'm using Facebox, and when I tried to change the content of a tag, it's giving me raw HTML but the rendered form, the code snippet is:

jQuery('#facebox .content').html("<%= escape_javascript(render :partial => 'form')%>");

Anybody has any idea about this? Thanks a lot.

A: 

That's most likely because HTML is converted into their entities representation thereby giving you raw html output. I am not a ruby guy, but possibly escape_javascript function does that as the name suggests.

Below example of juqery code should, for example, append the html rather than output raw html ouput:

$('#div').html($('#another_div').html());
Sarfraz
Yes, escape_javascript is used to escape the malicious stuff the user may input, but even without the escape_javascript, it doesn't work, I tried this, jQuery('#facebox .content').html("<h1>HHH</h1>")And it gives me the <h1>HHH</h1>
leomayleomay
@leomayleomay: Then it could be possible that facebox is already encoding it in raw html. Possibly facebook site has info about it.
Sarfraz
@Sarfraz, thanks a lot, I'll look into that
leomayleomay
@leomayleomay: Are you doing this BEFORE calling the facebox renderer or AFTER? And if after, then is the facebox currently visible on screen?
Raine
@Raine, what's facebox renderer? I'm using primitive Facebox, after I call jQuery('#facebox .content').html("<h1>HHHH</h1>"), the facebox is visible, but it gives me raw HTML but the rendered HTML
leomayleomay
A: 

@leomayleomay: By facebox renderer I meant the command that outputs the facebox on screen (there are multiple ways of doing that with facebox)

However, if all you want to do is change the content of the currently showing facebox, then you could call the command jQuery.facebox('some html');

If this doesn't work either, then may be you could give us a link to a page where you are testing this out

Raine
@raine, thanks for your reply, I did try the jQuery.facebox('some html'), it doesn't work either, and since the project is still under construction, I have no link to show you the unexpected result. Sorry
leomayleomay
@raine, I thought this has something to do with the form contains a file_field in it, ajaxSubmit will create a iframe to upload the file, and the returned Javascript snippet will go to the iframe, check this out, http://malsup.com/jquery/form/#file-upload
leomayleomay
this is good piece of information. How does your facebox fit into the flow? is the html content of the facebox that you inject gets sent to the server and then sent back? I'm just trying to recreate the process in my mind. Do you think it would be possible for you to set up a little test page that recreates the problem?
Raine