Can't figure out why Javascript is executing in one ajax request but not another.

11 views
Skip to first unread message

Rick DeNatale

unread,
Jul 7, 2008, 2:56:54 PM7/7/08
to prototype-s...@googlegroups.com
I've run out of ideas on this one.

I've got two rails controllers which are sharing some partials and ajax code.

One partial generates a pair of select elements one for country, and another for timezones.  It also generates an observer with:
<%= observe_field @user.dom_id('country_code'),
          :url => {:action => 'ajax_update_timezone_select_with_new_zones_for_selected_country',
               :timezoneable_type => 'User',
               :timezoneable_id => @user.id}, :method => :get, :with => 'country_code' %>

The ajax_update_timezone_select_with_new_zones_for_selected_country action is defined in a module mixed in to both controllers.  It renders an rjs template in which I've added an alert for debugging purposes:

page << 'alert("done");'
page.replace @entity.dom_id('timezone'), :partial => '/mixins/timezone/timezone_select', :locals => {:country_code => @country_code}


Now this works find in one controller, when I make a selection in the country_code selection list the observer fires, the alert comes up, and the timezone list is updated.

In the other controller the observer fires, the same response comes back, but nothing happens!  No alert, no update.

Firebug, shows the same response in both cases.  I've tried this both in Firefox and Safari and it seems browser independent.

I've gone so far as to cut and paste what firebug is showing  in the console along with the script tags for the observer, saving to two files and doing a diff between the two, and the only things which is changing are timestamps, and the hostname.

The hostname changes because we use different virtual hostnames to provide contexts in our app.  However, as far as I can tell the hostname is consistent between each response request pair, and the page containing the partial.

Any ideas on why Javascript is being executed in one case and thrown away in the other?

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Ruprict

unread,
Jul 8, 2008, 7:38:31 PM7/8/08
to Prototype & script.aculo.us
Can you post both responses here?

Rick DeNatale

unread,
Jul 9, 2008, 10:41:25 AM7/9/08
to prototype-s...@googlegroups.com
On Tue, Jul 8, 2008 at 7:38 PM, Ruprict <glenn.g...@gmail.com> wrote:

Can you post both responses here?

First I encourage everyone to carry this conversation to the new prototype scriptaculous forum

http://groups.google.com/group/prototype-scriptaculous/browse_thread/thread/1364afb7bca58888

That said here's what firebug is showing, first for the working request, then for the non-working one, I don't think that this is a DOM problem since in the non-working case the alert is never shown, so it looks like the javascript is not getting evaluated at all.

Working:

Params
country_code    AI
timezoneable_id    6644
timezoneable_type    User

Response Headers
Server    nginx/0.5.29
Date    Mon, 07 Jul 2008 18:00:44 GMT
Content-Type    text/javascript; charset=utf-8
Connection    keep-alive
Set-Cookie    neartime=6328c886a25842aeb21293c6919790db; domain=.development.near-time.com; path=/; expires=Thu, 05 Jul 2018 17:55:45 GMT
Status    200 OK
X-Runtime    0.22983
Etag    "9315af15ca940f80d119f9874b06848f"
Cache-Control    private, max-age=0, must-revalidate
Content-Length    616
Request Headers
Host    sa-space.development.near-time.com
User-Agent    Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0
Accept    text/javascript, text/html, application/xml, text/xml, */*
Accept-Language    en-us,en;q=0.5
Accept-Encoding    gzip,deflate
Accept-Charset    ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive    300
Connection    keep-alive
X-Requested-With    XMLHttpRequest
X-Prototype-Version    1.6.0.2
Referer    http://sa-space.development.near-time.com/events
Cookie    __utma=26861096.1409779322.1204576086.1215011433.1215023063.28; __utmz=26861096.1215023063.28.20.utmcsr=my.development.near-time.com:3000|utmccn=(referral)|utmcmd=referral|utmcct=/profile/edit; neartime=6328c886a25842aeb21293c6919790db; __utma=157920952.4221974457982456300.1211479843.1215448404.1215452953.11; __utmz=157920952.1215448404.10.6.utmcsr=my.development.near-time.com|utmccn=(referral)|utmcmd=referral|utmcct=/profile/edit; __utma=185682102.3820142486948954600.1214936559.1215444944.1215453488.6; __utmz=185682102.1215453488.6.4.utmcsr=my.development.near-time.com|utmccn=(referral)|utmcmd=referral|utmcct=/profile; __utmc=185682102; __utmc=157920952; __utmc=26861096; __utmb=157920952.2.10.1215452953; __utmb=185682102.2.10.1215453488

Response
try {

alert("done");

Element.replace("admin-6644-timezone", "\u003Cselect class=\"wide\" id=\"admin-6644-timezone\" name=

\"user[timezone_identifier]\"\u003E\u003Coption value=\"America/Anguilla\"\u003EAmerica/Anguilla\u003C

/option\u003E\u003C/select\u003E");

} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('alert(\"done\");\nElement.replace(\"admin-6644-timezone

\", \"\\u003Cselect class=\\\"wide\\\" id=\\\"admin-6644-timezone\\\" name=\\\"user[timezone_identifier

]\\\"\\u003E\\u003Coption value=\\\"America/Anguilla\\\"\\u003EAmerica/Anguilla\\u003C/option\\u003E

\\u003C/select\\u003E\");'); throw e }

This is the script from the HTML source which is making the AJAX request, again this is the working version:

<script type="text/javascript">

//<![CDATA[
new Form.Element.EventObserver('admin-6644-country_code', function(element, value) {new Ajax.Request('http://sa-space.development.near-time.com/events/ajax_update_timezone_select_with_new_zones_for_selected_country?timezoneable_id=6644&timezoneable_type=User', {asynchronous:true, evalScripts:true, method:'get', parameters:'country_code=' + value})})
//]]>

</script>

Not Working
Params
country_code    AI
timezoneable_id    6644
timezoneable_type    User

Response Headers
Server    nginx/0.5.29
Date    Mon, 07 Jul 2008 18:02:03 GMT
Content-Type    text/javascript; charset=utf-8
Connection    keep-alive
Set-Cookie    neartime=6328c886a25842aeb21293c6919790db; domain=.development.near-time.com; path=/; expires=Thu, 05 Jul 2018 17:55:44 GMT
Status    200 OK
X-Runtime    0.15805
Etag    "9315af15ca940f80d119f9874b06848f"
Cache-Control    private, max-age=0, must-revalidate
Content-Length    616
Request Headers
Host    my.development.near-time.com
User-Agent    Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0
Accept    text/javascript, text/html, application/xml, text/xml, */*
Accept-Language    en-us,en;q=0.5
Accept-Encoding    gzip,deflate
Accept-Charset    ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive    300
Connection    keep-alive
X-Requested-With    XMLHttpRequest
X-Prototype-Version    1.6.0.2
Referer    http://my.development.near-time.com/profile/edit
Cookie    __utma=26861096.1409779322.1204576086.1215011433.1215023063.28; __utmz=26861096.1215023063.28.20.utmcsr=my.development.near-time.com:3000|utmccn=(referral)|utmcmd=referral|utmcct=/profile/edit; neartime=6328c886a25842aeb21293c6919790db; __utma=139263919.2051287913.1204576345.1215022160.1215453483.67; __utmz=139263919.1215453483.67.28.utmcsr=sa-space.development.near-time.com|utmccn=(referral)|utmcmd=referral|utmcct=/events; __utma=185682102.3820142486948954600.1214936559.1215444944.1215453488.6; __utmz=185682102.1215453488.6.4.utmcsr=my.development.near-time.com|utmccn=(referral)|utmcmd=referral|utmcct=/profile; __utmc=185682102; __utmc=26861096; __utmc=139263919; __utmb=139263919.2.10.1215453483; __utmb=185682102.3.10.1215453488

Response
try {

alert("done");

Element.replace("admin-6644-timezone", "\u003Cselect class=\"wide\" id=\"admin-6644-timezone\" name=

\"user[timezone_identifier]\"\u003E\u003Coption value=\"America/Anguilla\"\u003EAmerica/Anguilla\u003C

/option\u003E\u003C/select\u003E");

} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('alert(\"done\");\nElement.replace(\"admin-6644-timezone

\", \"\\u003Cselect class=\\\"wide\\\" id=\\\"admin-6644-timezone\\\" name=\\\"user[timezone_identifier

]\\\"\\u003E\\u003Coption value=\\\"America/Anguilla\\\"\\u003EAmerica/Anguilla\\u003C/option\\u003E

\\u003C/select\\u003E\");'); throw e }

And here's the javascript from the HTML source.

<script type="text/javascript">

//<![CDATA[
new Form.Element.EventObserver('admin-6644-country_code', function(element, value) {new Ajax.Request('http://my.development.near-time.com/profile/ajax_update_timezone_select_with_new_zones_for_selected_country?timezoneable_id=6644&timezoneable_type=User', {asynchronous:true, evalScripts:true, method:'get', parameters:'country_code=' + value})})
//]]>

</script>

Rick DeNatale

unread,
Jul 9, 2008, 10:43:58 AM7/9/08
to prototype-s...@googlegroups.com
I cross posted to the old group and got a request for the responses, I've replied there but I'm also re-posting here since this is where the conversation should be taking place:


On Tue, Jul 8, 2008 at 7:38 PM, Ruprict <glenn.g...@gmail.com> wrote:

Can you post both responses here?


Here's what firebug is showing, first for the working request, then for the non-working one, I don't think that this is a DOM problem since in the non-working case the alert is never shown, so it looks like the javascript is not getting evaluated at all.
Reply all
Reply to author
Forward
0 new messages