function changeDeliveryTime() {
var deliveryMethod = $('#deliveryMethod').val();
var delAddress = $('#delAddress').val();
var schedule = $('#scheduleko').val();
$.ajax({
type : "GET",
url : "/ajaxchangedeliveryschedule.do?deliveryMethod=" + deliveryMethod + "&address=" + delAddress + "&scheduleId=" + schedule,
success : function(response) {
//successfully change the time
//alert('successfully change the time');
},
error : function(e) {
alert('Error changing time schedule: ' + e);
}
});
}
Javascript Example To Call an Ajax
Example code in javascript to call an ajax
another method is
ReplyDelete$.get("/basketcount", function (data) {
console.log('hello')
console.log(data);
console.log('hello')
}, "json"); // or xml, html, script, json, jsonp or text
Another method
ReplyDeletevar paramObj = new Object();
paramObj.id = currentInput.attr('id');
paramObj.field = currentInput.attr('field');
paramObj.newvalue = newValue;
$.ajax({
method: 'POST',
url: '/customervalueedit',
data: paramObj
}).done(function (result) {
$.simplyToast("Changes saved successfully", 'success');
}).error(function (error) {
$.simplyToast("Error in editing description: " + error.message, 'warning');
});
longer method
ReplyDeletevar url = '/customervalue';
var posting = $.post(url,
{
customer_id: customerId,
title: $('#' + secId + 'value').val(),
description: $('#' + secId + 'desc').val(),
templatecomponent_id: valueId,
sort_order: $('#' + secId + 'order').val(),
});
posting.done(function (data) {
console.log(data);
$.simplyToast('Saved successfully', 'success');
}).fail(function (err) {
console.log(err);
$.simplyToast('Error in saving record', 'error');
});
Rails controller
ReplyDeletebegin
tempvalue = Templatecomponentvalue.new
tempvalue.update_attributes(values_params)
tempvalue.save
render:json => {:message => 'Saved successfully'}, :status => 200
rescue => ex
render:json => {:errors => ex.message}, :status => 422
end