简体   繁体   中英

ajax doesnt pass variable to php script

Hi i cant get this script to work the update script works fine but this doesnt seem to pass any variables to the update qty page

<script type='text/javascript'>

function updateqty() {

   var str = $(this).attr('name'); 
   var orderCode = str.slice(9, -1);
   var quantity = $(this).value; 
   var xmlhttp = new XMLHttpRequest(); 

   xmlhttp.onreadystatechange = function() 
   {
      xmlhttp.open("GET","updateqty.php?id=" + orderCode + "&qty=" + quantity, true);
      xmlhttp.send();
   }
}

</script>

<input type='text' name='quantity[701]' size='3' tabindex='1' onblur='updateqty(this)' />

You might want to define xmlhttp. They're not reusable, after all.

 var xmlhttp = new XMLHttpRequest();

This will not be cross-browser compliant as it will fail on old IE. You're using jQuery for the name selection - why don't you make use of jQuery.ajax ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM