Troubleshooting Ajax Responses

Need to see Javascript generated by an Ajax helper in an Ajax response? Well, you won’t be able to see it by viewing source because, since it’s an Ajax response rendered by Javascript, it’s not technically part of the source at all.

But you can still see the Javascript—and what may be going wrong—like thus:

<%=h yourjavascripthelper() %>

The ‘h’ is an ERb method which will convert everything to HTML entities. Which means that as long as your response is showing up at all, you will now be able to see this Javascript with a minimum of hassle.

Stympy from #rubyonrails also notes that you can use the View Formatted Source Firefox extension to similar effect. But if you have a lot of source, it seems to me that just echoing the Javascript as above will make it easier to find.

7 Comments

  1. Geoff says:

    You can also just dial up the url in your browser and see a partial rendering:

    http://0.0.0.0:3000/funky/ajax_function?param=Krusty_the_klown

  2. Geoff says:

    I take back everything I said now that I’ve tried the plugin….

    That’s a great plugin and will make me at least 16% more productive.

    Thanks!

  3. Amy says:

    I like the very precise quantification of that productivity boost, Geoff. :)

  4. Dreambaby Gate

    slash7 with Amy Hoy » Blog Archive » Troubleshooting Ajax Responses

  5. tall pet gates

    slash7 with Amy Hoy » Blog Archive » Troubleshooting Ajax Responses

  6. super wide safety gate

    slash7 with Amy Hoy » Blog Archive » Troubleshooting Ajax Responses

  7. natural parenting

    slash7 with Amy Hoy » Blog Archive » Troubleshooting Ajax Responses

Hey, why not get a shiny
Freckle Time Tracking
account?