Jump to content

Uncaught ReferenceError: $ is not defined


zero_ZX

Recommended Posts

Hi,

So there have probably been loads of those questions however from what I've searched I have not been able to find the answer.

So I receive this error, when using this function:

function updateCart(row_id, item_qty)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  document.getElementById("item_place").innerHTML = xmlhttp.responseText;
    }
  }
xmlhttp.open("POST",'<?php echo site_url("votepoints/updateCart/");?>',true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", row_id.length);
xmlhttp.setRequestHeader("Connection", "close")
xmlhttp.send("row_id="+row_id+"&item_qty="+item_qty);
}

 

The problem is the row_id  item_qty works fine for some reason. I guess the difference is that qty is an int, and id is a string.

Right, so Before the function i decided to put var row_id = ""; to see if that fixed the problem. Apparently it didn't.

I'm calling the function via a link: javascript:updateCart(e22659b1a980aaca47048bebd5523817, 2)

And this string generates this error for some reason, and I have no idea why.

Link to comment
Share on other sites

I'm calling the function via a link: javascript:updateCart(e22659b1a980aaca47048bebd5523817, 2)

 

Your first parameter, the hash value, has to be enclosed in quotes since it contains letters.

javascript:updateCart("e22659b1a980aaca47048bebd5523817", 2)

 

 

If your echoing it out with PHP you can use json_encode to get the proper formatting for strings (or other values).  For example (use whatever the actual variable is):

javascript:updateCart(<?php echo json_encode($row_hash); ?>, 2)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.