I have updated a stock value for product on button click, I want to change my ajax code to magento prototype ajax. My code :
<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>
My ajax code is:
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);
}
})
Now I want to change this ajax to prototype ajax. but i am not able to do.
My prototype 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" );
}
Can anyone help me? Thanks in advance