zero_ZX Posted April 28, 2012 Share Posted April 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261752-uncaught-referenceerror-is-not-defined/ Share on other sites More sharing options...
kicken Posted April 28, 2012 Share Posted April 28, 2012 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) Quote Link to comment https://forums.phpfreaks.com/topic/261752-uncaught-referenceerror-is-not-defined/#findComment-1341328 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.