Tony Montana
Tony Montana

Reputation: 45

JavaScript works fine in any browser but Firefox?

Ok this is my JavaScript

<script type="text/javascript" language="JavaScript">
function manageCart(task,item) {
var url = 'managecart.php';
var params = 'task=' + task + '&item=' + item;
var ajax = new Ajax.Updater(
          {success: ''},
          url,
          {method: 'get', parameters: params, onFailure: reportError});
}

function reportError(request) {
$F('cartResult') = "An error occurred";
}

And this is HTML

<p>
<a href="javascript:void(0)" onclick="manageCart('add',83)">Add to cart</a>
</p>

This script doesn't work in Firefox, I've ran a few Firefox JS debuggers but they displayed no errors. I'm not so good in JavaScript so please help me if you can :) This script actually uses Prototype library if it will make things clearer.

Upvotes: 0

Views: 133

Answers (2)

Tony Montana
Tony Montana

Reputation: 45

I've spent more time in FireBug and found the error.

Timestamp: 03.04.2013 10:36:38 Error: ReferenceError: invalid assignment left-hand side Source File: http://www.example.com/index.php Line: 413, Column: 18 Source Code:

('cartResult') = "An error occurred";

Firefox desperately wanted for the statement to look like this:

('cartResult') == "An error occurred"; 

Upvotes: 0

Geek Num 88
Geek Num 88

Reputation: 5312

For this type of Ajax call do not use Ajax.Updater as that is designed to update a specific element with the contents of the ajax response. I believe that you want to just make a simple single ajax call so using Ajax.Request would be what you want to use.

Original Code using Ajax.Updater

var url = 'managecart.php';
var params = 'task=' + task + '&item=' + item;
var ajax = new Ajax.Updater(
      {success: ''},
      url,
      {method: 'get', parameters: params, onFailure: reportError});

Code using Ajax.Request

var url = 'managecart.php';
var params = 'task=' + task + '&item=' + item;
var ajax = new Ajax.Request(url,
     {
          method: 'get',
          parameters: params,
          onFailure: reportError,
          onSuccess: function(){
              console.log('It Worked');
          }
     });

I put a success handler in this call just to confirm that it worked for you - and it should output to your console. You can remove it or comment the console.log() when you are satisfied it works

Upvotes: 1

Related Questions