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
https://forums.phpfreaks.com/topic/261752-uncaught-referenceerror-is-not-defined/
Share on other sites

  Quote

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.