Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

when I try and use the index action to have a link to the show action nothing is rendered on screen if I used :remote => true in the link_to, yet in the rails server output it says rendered the show JS as well as anything I insert into the show.js.erb say like a partial but never shows up in the browser

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

The show.js.erb should only return the HTML of the content you want returned. The code in your javascript file does the $("#refreshable") html replacement.

Also, in your replacementContent function, the url needs to be set, probably to /show, depending on the route of the controller you're wanting to call.

Make sense? Try those and give me an update

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

I'd like the url to be the show for the item plus its ID ... how would I pass the url the path for the item programmatically?

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

is there something I'm missing in the JS...
if I run it through firebug it thinks the replaceContent() function is an unfound anonymous function and missing a parameter?

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

i think the replaceContent is being defined in the wrong place perhaps? as firebug thinks it is not defined.

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

Your line in javascript should be this (remove the parentheses from the function name):

setInterval("replaceContent", 10000);

To load the exact page you're on, for your URL in the javascript code put this:

document.URL
Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

ok so the page isn't cascading itself anymore though not updating in the browser.

its showing in the rails server that its rendering the index action not the show... and i'm explicitly on the show page in the browser for an item.

the div I have to refresh is as ID ... should it perhaps be a class instead?

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

ID is preferred for a single element.

For the ajax URL, try passing the exact URL to the item directly. See what happens.

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

only problem with the exact url is that it will change dependent on the item ID

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

though I think

var pathname = window.location.pathname;

might work to get that

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

djronin47 wrote:

only problem with the exact url is that it will change dependent on the item ID

True, but right now we're debugging to find the problem why it's not working

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

ok I'm giving an explicit path now and decreased the refresh time interval so I can see faster

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

and now it doesn't seem to update at all.

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

only other change i made was moving the div id that's being refreshed high up into the show.html.erb file vs nested further down and wrapped around the entire partial(s) i want changed

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

I'm having a hard time trying to help without actually seeing everything in action, sorry hmm Any chance you could put it online, or allow me to access it? If not, that's fine, but I'm getting to the point where everything is just sounding crazy and I can't make sense of it, haha.

I've done a lot with rails and ajax in my applications, it's just hard to give tips when I can't see the exact problems.

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

i will try and outline it as best as possible..

I have an index view that is simply listing all items and some of their attributes to the user
there is an if statement in the view if one of those items is not doing an action (the rails app is kicking off some server side back end stuff),

if it is doing something the link_to displays show status (with the :remote => true wasn't working), if they click this it goes to the show page, if not they can go to the edit action to start a process (this part works but doesn't need to refresh automatically)

once they click on the show action it lists some of the item's attributes and again use the ajax to update automatically in the background, the status attribute being updated by a server side action running on the system.

I hope that might help a little bit.

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

I have solved this by changing the js used.

setInterval( function() {
  $("#refreshable").load(location.href+" #refreshable>*", "");
}, 5000);

This properly updates the div ID and nothing else and doesn't cause a cascade of a page within a page.

Thank you for your assistance on this.

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

Looks good to me smile Glad it's working. Be sure to post back with more questions if you have them

Last edited by wesf90 (2012-03-02 18:45:16)

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!

Re: [SOLVED] how to refresh div using ajax? (rails 3.2)

To see a WOW Gold and Buy RS Gold world in a granda of stand.And a heaven in a wild flower.Hold infinity in the palm your hand and eternity in an hour.