List Info

Thread: Getting just a piece of code from AJAX response




Getting just a piece of code from AJAX response
user name
2007-12-26 10:08:02
I have this code:
	new Ajax.Request(url,
		{
			method: 'get',
			onSuccess: function(transport)
			{
				var element = document.createElement("div");
				Element.extend(element);
				element.innerHTML = transport.responseText;
				$('content-title').update(element.getElementsBySelector(
'#title')
[0].innerHTML);
				$('content-text').update(element.getElementsBySelector('
#content')
[0].innerHTML);
			}
		}
	);

The file I'm loading looks like:
<div id="title">...</div>
<div id="content">...</div>
and I want to set the content of "title" to div
element "content-
title" and content of "content" to
"content-text". This code is
working fine in FF, Opera, etc. but in IE6 and IE7 it does
nothing.
When I remove innerHTML and left only
element.getElementsBySelector('#*')[0] it inserts some empty
object.

Can somebody help me how to solve this problem?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Getting just a piece of code from AJAX response
user name
2007-12-26 11:29:00
1) Make sure you're running the latest version (1.6)
2) I'm not sure how well IE handles selectors on uninserted
elements
so it would be safer to append it to the document first.

$(document.body).insert(new Element('div', {id:
'_proxy'}).hide());

3) Ajax.Updater is more appropriate when updating elements
via ajax

new Ajax.Updater('_proxy', url, {
  method: 'get',
  onComplete: function() {
   
$('content-title').update($('_proxy').down('#title').innerHT
ML);
   
$('content-text').update($('_proxy').down('#content').innerH
TML);
  }
})

4) It would be more convenient if your server could return
JSON
instead of an html {"title": "foo",
"content": "bar"}. The above
snippet would only take few lines:

new Ajax.Request(url, {
  method: 'get',
  onSuccess: function(resp) {
    var data = resp.responseJSON;
    $('content-title').update(data.title);
    $('content-text').update(data.content)
  }
})


Best,
kangax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Getting just a piece of code from AJAX response
user name
2007-12-26 12:24:58
Thanks, the 2nd point was the problem. And also thanks for
tips.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Getting just a piece of code from AJAX response
user name
2007-12-26 14:42:26
The responseJSON is null (and json in function parameter was
null
too). Can you tell me why?
Anyway I've used responseText.evalJSON().
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Getting just a piece of code from AJAX response
user name
2007-12-26 15:33:47
JSON responses must have a Content-type header of
application/json
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Getting just a piece of code from AJAX response
user name
2007-12-27 04:57:16
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )