1

I'm new around so if I'm missing some info or something, please let me know and I'll provide it. I've already looked for informationg regarding this error, but I haven't found anything relevant yet. So, here's the deal.. Some of my controllers actions are being called twice, and I've just noticed that when I was wondering why was I sending SOME mails twice (the application I've got has an email client incorporated).. and only then after logging what was I doing I noticed the controller gets called twice... By the way, this only happens when I called the action from a link outside the application or by typing the url. If I'm not making myself clear or I'm missing something, please do post here anyway so I can add more info..

Thanks in advance!

IWannaLearn
  • 21
  • 1
  • 2
  • For sure a little bit of code would help. Are you sure you do not redirect back to the controller?Like I said post relevant code. – Iznogood Aug 17 '10 at 16:54
  • 1
    Also, can you post some more information about the codebase? Did you use a framework (which one and which version if so)? Any other possibly pertinent details? – ircmaxell Aug 17 '10 at 16:56
  • Might be relevant: http://stackoverflow.com/questions/2009092/page-loads-twice-in-google-chrome - see accepted answer. :) (Some of the others are quite good ideas, too.) Also http://stackoverflow.com/questions/2153579/page-load-fires-twice-on-firefox-please-help – pinkgothic Aug 17 '10 at 16:56
  • 1
    Please include the code from your email page, your ajax code, and details about any authentication system that might be causing redirects. – Ian Wetherbee Aug 17 '10 at 16:56

6 Answers6

7

Aggregating possible answers from other sources as per my comment:

  1. <img src="" /> and relatives.

    If you have places where you generate the src attribute of the img tag, make sure it isn't empty in any freak cases; a handful of browsers take the empty src as a prompt to load the page again. 1, 2, 3

    The same is true for an empty favicon, javascript or css href - generally anything where you're asking the browser to fetch an external resource, but no url is supplied, even in css1.

    The phenomenom is perhaps a more understandable if you consider, for example, where you're sending form data when you do <form action=""> (or even just <form>) - namely the same page.

  2. .htaccess shenanigans.

    Check your rewrite rule(s): Are you making the server take a roundtrip to your script for any static content (e.g. favicon1)? Do non-existent files trigger a call to your script, and is an external resource link pointing to one (e.g. an ancient css stylesheet that was finally deleted from the filesystem but someone forgot to remove it from the HTML source)?

  3. Browser-based debuggers.

    Some browser-based debuggers, e.g. firebug1, will send a second request to the page depending on circumstances, to gather data that wasn't natively supplied to them by the browser itself. Make sure you're not getting that.

See if any of those help you.

Community
  • 1
  • 1
pinkgothic
  • 6,081
  • 3
  • 47
  • 72
  • thanks alot for this. i had the same problem, but in codeigniter. I has calling a controller, but the controller has being called twice. The problem was a bad formated src tag thanks alot :D – Pedro Luz Apr 11 '11 at 13:55
3

For me, having Firebug open was causing the page to be called twice.

2

Without seeing the actual application code, I'm left to simply guess - however, I know of at least one semi-famous bug in this arena, see http://blog.codekills.net/archives/27-Fun-with-Firefox-Jitters.html for the details - basically, it happens when a <tr> has an onclick handler and an <a> inside that goes to the same URL...and even if this isn't what your app does, perhaps you can gain some insight from seeing how they went about debugging the problem.

TML
  • 12,813
  • 3
  • 38
  • 45
  • I am sorry I haven't provided any application code... but the code is just too big hehe.. that's why I was looking for a more generic answer like yours. Ok so, when I turned the JS off, it called the controller action once, but of course, didn't get to finish loading the whole page.. so then I checked through FireBug that AJAX is calling the controller action once more. Seems like I'm getting a little bit closer to the solution.. thanks! Gonna check that onclick thing you mentioned as well – IWannaLearn Aug 17 '10 at 17:56
  • Bleh.. I have debugged the JS with FireBug.. and everything looks fine.. That means that it's doing something like: 1- call controller action 2- go through all the javascript code 3- call controller action again Still stucked :/ – IWannaLearn Aug 18 '10 at 16:42
  • Capture the history with LiveHttpHeaders and post it so we can see the request chain? – TML Aug 19 '10 at 07:05
0

After hours of debugging, my issue was a dynamically set background-image css tag. If there was no image - background-image:url() - a second request would be made back to the controller once the page was loaded.

Just in-case anyone else is doing the same.

Mr Zorn
  • 1,903
  • 1
  • 14
  • 25
0

My particular version of the problem and fix

  • submitting this form worked on a production server, but not "localhost"
  • For Firefox: form worked in both places. For Chrome: only worked on production server
  • setting breakpoints in my problem controller confirmed it was getting called multiple times (duh) and CSRF protection on that form got gibbered up as a result.

Then I found this thread: http://ellislab.com/forums/viewthread/210318/

My solution involved the favicon. The src attribute wasn't quite right. I did have a favicon in the root directory and it loaded on the hompage but not others (didn't notice that for a while). Anyways, providing an absolute path to the favicon solved it

Don't really know if you MUST have a favicon, but like mentioned above, make sure any resources you pull in (img/js/css) are properly referenced so as to avoid a browser retrying to request a page

0

On my Code Igniter View, I have a Form. THe form has a Post method calling url of controllerA. On clicking Add button in the form, I was calling a Javascript function that validates email ID. After validating email in .js, I was posting some data using $.post(url...) to the controllerA for database insertion. The insert was happening twice.

It turned out that in the $.post(url) I was calling controllerA url. When I commented that $.post, database insert worked fine.

Soumya Rajiv
  • 87
  • 1
  • 4