magento中的原型Ajax

时间:2015-09-02 06:43:13

标签: javascript php jquery ajax magento

我已点击按钮点击产品的库存值,我想将我的ajax代码更改为magento原型ajax。 我的代码:

       <tr>
        <input type="hidden" class="product_id" id="product_id" value="<?php echo $_obj->getId() ?>"/>
        <td><?php echo $_obj->getId() ?></td>
        <td><span class="nobr"><?php echo $_obj->getName(); ?></span></td>
        <td id="stock-qty<?php echo $_obj->getId() ?>"><?php echo round($_obj->getQty()); ?></td>
        <td><span class="nobr"><input type="text" name="update-stock" id="update-stock" value="<?php echo round($_obj->getQty()); ?>" class="update-stock validate-number"/>
         <button type="submit" name="stockupdate" class="stockupdate" value="Submit">Update</button> 
        </td>

我的ajax代码是:

        jQuery('.stockupdate').click(function() {
 jQuery('#loading-mask').show();
    var update_stock = jQuery(this).parents('tr').find('.update-stock').val();
    var numberRegex = /^[+-]?\d+(\.\d+)?([eE][+-]?\d+)?$/;
    var product_id = jQuery(this).parents('tr').find('.product_id').val();
    var url = "<?php echo Mage::getUrl('marketplace/vendor/stockupdate'); ?>";
    jQuery('.success-message').html('');
    if(update_stock!="" && numberRegex.test(update_stock)) {
     jQuery.ajax({
         type: "POST",
           data: ({updatestock: update_stock , product_id: product_id}),
           url: url,
           success: function (result) {
                jQuery('.success-message').html('');
                if(result != 'null'){
                jQuery('#loading-mask').hide();
                jQuery('#stock-qty'+product_id).text(result);
                var message = "<div class='success-message' style='color:green;'>Updated Successfully.</div>";
                jQuery('#stock-qty'+product_id).next('td').find('.update-stock').after(message);
                }
           }
     });
     }else{
        var message = "<div class='success-message' style='color:red;'>Please enter the number.</div>";
        jQuery('#stock-qty'+product_id).next('td').find('.update-stock').after(message);
     }
})

现在我想将此ajax更改为原型ajax。但我无法做到。

我的原型ajax:

      function SubmitRequest()
  {         
var update_stock = jQuery(this).parents('tr').find('.update-stock').val();
var numberRegex = /^[+-]?\d+(\.\d+)?([eE][+-]?\d+)?$/;
var product_id = jQuery(this).parents('tr').find('.product_id').val();
var url = "<?php echo Mage::getUrl('marketplace/vendor/stockupdate'); ?>";
jQuery('.success-message').html('');
if(update_stock!="" && numberRegex.test(update_stock)) {
  new Ajax.Request(url, {
  method: 'POST',
  parameters: ({updatestock: update_stock , product_id: product_id}),
  onSuccess: successFunc,
  onFailure:  failureFunc
  });
 }
 }
 function successFunc(response){
 alert(response);
 if (200 == response.status){
    alert("Call is success");
 }
 var container = $('notice');
 var content = response.responseText;
 container.update(content);
  }

 function failureFunc(response){
 alert("Call is failed" );
   }

任何人都可以帮助我吗? 提前致谢

0 个答案:

没有答案