jQWidgets Forums
jQuery UI Widgets › Forums › Grid › ajax call is not wokring if i use it under set intrval
Tagged: setInterval
This topic contains 1 reply, has 2 voices, and was last updated by Peter Stoev 10 years, 8 months ago.
-
Author
-
my ajax stops working if i write it under setInterval function.
can you please tell me what I missed? do i have to write something else?
$(document).ready(function() {
//===========================
// show the grid for email Group
//===========================
var url = “/settings/createemailgroupjson”; // action from where we get the result in json
var source = {
datatype: “json”,
datafields: [{
name: ‘groupName’, type: ‘string’ },
],
updaterow: function(rowid, rowdata, commit) {
// synchronize with the server – send update command
},
id: ‘id’,
url: url,
pagesize: 30,
};var dataAdapter = new $.jqx.dataAdapter(source);
var editrow = -1;// initialize jqxGrid
$(“#jqxgrid”).jqxGrid({
width: 400,
theme: KiouiTheme,
height: 350,
source: dataAdapter,
pageable: true,
autoheight: true,
sortable: true,
altrows: true,
enabletooltips: true,
pagesizeoptions: [’10’, ’20’, ’30’, ’40’],
showfilterrow: true,
filterable: true,
showtoolbar: false,
enablebrowserselection: true,
// columns shown in grid are mention below
columns: [{
text: ”,
datafield: ‘Edit’,
width: 50,
columntype: ‘number’,
filterable: false,
sortable: false,
cellsrenderer: function() {
return ‘<div style=”width: 100%”></div>’;
}
}, {
text: ‘Group Name’,
datafield: ‘groupName’,
width: 300
}, {
text: ”,
datafield: ‘Delete’,
width: 50,
columntype: ‘number’,
filterable: false,
sortable: false,
cellsrenderer: function() {
return ‘<div></div>’;
}
}, ]});
// initialize the popup window and buttons.
$(“#popupWindow”).jqxWindow({
width: 750,
height: 130,
resizable: false,
isModal: true,
autoOpen: false,
cancelButton: $(“#cancel”),
modalOpacity: 0.01,
theme: KiouiTheme
});// update the edited row when the user clicks the ‘Save’ button.
$(“#Save”).click(function() {if (editrow >= 0) {
var refreshInterval = setInterval(function () { // setting intervalvar rowID = $(‘#jqxgrid’).jqxGrid(‘getrowid’, editrow);
var row = {
groupName: $(“#groupName”).val(),
id: rowID,
};
// ajax called to UPDATE the row on edit$.ajax({
url: ‘/settings/addemailgroupajax’,
data: row,
type: “POST”,
cache: false,
async: false,
success: function(response) {
if (response == “success”) {} else {
alert(‘Something went wrong please try again.’);
}
},
error: function(response) {
// cancel changes.
alert(‘Something went wrong please try again.’);
}
});// $(‘#jqxgrid’).jqxGrid(‘updaterow’, rowID, row);
$(“#popupWindow”).jqxWindow(‘hide’);}, 5000); //5 seconds
}
});// on click of edit and delete
$(“#jqxgrid”).on(“cellclick”, function(event) {
var column = event.args.column;
var rowindex = event.args.rowindex;
var columnindex = event.args.columnindex;//when user wants to edit the record
if (columnindex == 0) {// open the popup window when the user clicks a button.
editrow = rowindex;
var offset = $(“#jqxgrid”).offset();
$(“#popupWindow”).jqxWindow({
position: {
x: parseInt(offset.left) + 60,
y: parseInt(offset.top) + 60
}
});
// get the clicked row’s data and initialize the input fields.
var dataRecord = $(“#jqxgrid”).jqxGrid(‘getrowdata’, editrow);
$(“#groupName”).val(dataRecord.groupName);// show the popup window.
$(“#popupWindow”).jqxWindow(‘show’);};
// if user click want to delete record
if (columnindex == 2) {
if (confirm(‘Are you sure you want to delete this record?’)) {
deleterow = rowindex;
var rowID = $(‘#jqxgrid’).jqxGrid(‘getrowid’, deleterow); // fetch the deleted id
var del = “param=delete&id=” + rowID;
$.ajax({
url: ‘/settings/deleteemailgroupajax’,
data: del,
type: “POST”,
cache: false,
async: false,
success: function(response) {
if (response == “success”) {
window.location.reload();
}
}
});
};
};
});//======================================================
// called ajax to save the data on click of “add template”
//=======================================================
$(“#addRecord”).click(function() {// setInterval(function(){ // setting interval
//alert(‘qwerty’);$.ajax({
url : “/settings/addemailgroupajax”,
type : “POST”,
cache: false,
async: false,
data : $(“#addForm”).serialize(),
success: function(response) {
if (response == “success”) {
$(‘#TempForm’).jqxWindow(‘close’);
window.location.reload();
}
}
});
$(“#addForm”).submit(function() {
return false;
});// }, 1000); //setting interval the constant is define in config.php file
});});// end document readyfunction
//==================================================================
// window open in email group view
//==================================================================
var basicDemo = (function() {
//Adding event listeners
function _addEventListeners() {
$(‘#addrowbutton1’).click(function() {
$(‘#SystemEmailgroupGroupGroupName’).val(”);$(‘#TempForm’).jqxWindow(‘open’); // to open the window onclick of open button
});
$(‘#hideWindowButton’).mousedown(function() {
$(‘#TempForm’).jqxWindow(‘close’); // to close the add window onclick of cancel button
});
$(‘#cancel’).mousedown(function() {
$(‘#popupWindow’).jqxWindow(‘close’); // to close the edit window onclick of cancel button
});
};//Creating all page elements which are jqxWidgets
function _createElements() {
$(‘#addrowbutton1′).jqxButton({
width: ’70px’,
theme: KiouiTheme
});
};//Creating the window
function _createWindow() {
$(‘#TempForm’).jqxWindow({
showCollapseButton: true,
maxHeight: 130,
maxWidth: 750,
minHeight: 130,
minWidth: 650,
height: 130,
width: 750,
autoOpen: false,
theme: KiouiTheme,
initContent: function() {
$(‘#TempForm’).jqxWindow(‘focus’);
}
});
};
return {
config: {
dragArea: null
},
init: function() {
_createElements();
_addEventListeners();
_createWindow();
}
};
}());$(document).ready(function() {
//Initializing the demo
basicDemo.init();
});HI pankhi,
From your code, I do not understand the idea of that setInterval. Do you want to update the same record multiple times with the same data? If your Ajax stops working if you write it in setInterval, then my suggestion is: check your page for syntax error or any errors that appear in the console window, i.e debug this with a debugger like Chrome’s DevTools.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.