I need to get the emailid value from one json formated list the list is like i mentioned below
result:::[{name=sudersan san, emailid=divya.vairavel#gmail.com}, {name=Sasi Guru, emailid=ragavendran.kesavan#gmail.com }]
so please guys suggest me how can i get the emailid from above
i have tried the code in javascript for splitting.
if(data1.length >0 ){
for (var k = 0; k < data1.length; k++) {
var emailid= data1[k].emailid
var intname= data1[k].intname
var datevalue = localStorage.getItem("datevalue");
var sessiontime = localStorage.getItem("sessiontime");
$.ajax({
url: "clientinteractoremail",
type:"POST",
data : {
emailid : emailid,
datevalue : datevalue,
sessiontime : sessiontime,
intname : intname
},
success: function(data1) { },
});
}
}
var result = [
{
name="sudersan san",
emailid="divya.vairavel#gmail.com",
},
{
name="Sasi Guru",
emailid="ragavendran.kesavan#gmail.com",
}]
Those statements pull the values from this:
for(int i = 0 ; i<result.length;i++){
console.log(result[i].name);
console.log(result[i].emailid);
}
you try this
Related
I have a loop from an array and what it does is before saving it in datatable it will check if the item exsist in database and here is the code
for (i = 0, len = array.length; i < len; i++) {
var item_code = array[i][1];
var description = array[i][2];
var qty = array[i][0];
if (item_code != "") {
console.log(item_code);
var if_exsist = function () {
var tmp = null;
$.ajax({
url: "../program_assets/php/web/stocks_excel_insert_transactions.php",
data: {
saving_mode : 'check_item',
item_code : item_code
},
'async': false,
type: 'post',
success: function (data) {
var data = data.trim();
if (data == 0) {
tmp = "no"
$('#btn_save').prop('disabled', true);
} else {
tmp = "yes"
}
}
});
return tmp;
}();
tbl_delivery_list.row.add({
"docket_number" : docket_number,
"from" : from,
"from_id" : from_id,
"to" : to,
"to_id" : to_id,
"item_code" : item_code,
"description" : description,
"qty" : comma(qty),
"exsist" : if_exsist
}).draw( false );
counter++;
}
}
the code above will work but my problem is how can I incorporate a progress bar? loading sample. I add this code but the loading happens after all the work has been done.
progress = counter / array.length;
progress = progress * 100;
$(".bar").css("width", progress + "%");
my target here is to update the progress bar one by one after doing the code on the 1st one
I hope someone can help me with this issue that I have.
I'm trying to pass an array into controller with JavaScript like this:
$('#send') .lick(function () {
var items = {};
var grid = $('#grid') .ata('kendoGrid');
var selectedElements = grid .elect();
for (var j = 0; j < selectedElements .ength; j++) {
var item = grid .ataItem(selectedElements[j]);
items['grid[' + j + '] .arecidoCodigo'] = item .arecidoCodigo;
}
$ .jax({
type: "POST",
data: items,
url: '#Url .ction("Index", "Busqueda")',
success: function (result) {
console .og(result);
}
})
})
This works fine.
But when I tried to pass another value, in this case a string data, the array is sending null into the controller but the string value is not null.
This is my code when I tried to send another value, in this case the array and the string data:
$('#send') .lick(function () {
var items = {};
var grid = $('#grid') .ata('kendoGrid');
var selectedElements = grid .elect();
var enviarDest = $('#destinatario') .al();
for (var j = 0; j < selectedElements .ength; j++) {
var item = grid .ataItem(selectedElements[j]);
items['grid[' + j + '] .arecidoCodigo'] = item .arecidoCodigo;
}
var postData = { marcas: items, destinatario: enviarDest };
$ .jax({
type: "POST",
data: postData,
url: '#Url .ction("Index", "Busqueda")',
success: function (result) {
console .og(result);
}
})
})
And this is the code of my controller:
public async Task<ActionResult> Index(List<MarcaParecido> marcas, string destinatario)
{
..
}
Here is when I receive the list marcas null and the string destinatario is not null, I don't know what am I doing wrong.
Try using JsonResult instead of async in your controller:
public JsonResult Index(List<MarcaParecido> marcas, string destinatario)
{ .. }
I have a form collecting employee production data, the following is the code:
$(document).on('click','input#Apply.btn.btn-success',function(e){
var TableData;
TableData = storeTblValues();
var TableData1 = [];
$.each(TableData,function(index,value){
if(value.quantity && value.quantity >0 && value.quantity < 65535){
TableData1[index]={
"employee_id" : value.employee_id
, "operation_id" : value.operation_id
, "quantity" : value.quantity
}
}
});
// retrieving employee_id to fetch date data from date input
$.each(TableData1,function(index,value){
employee_idj = value.employee_id;
});
$('#cboxClose').click();
var datee = dateConvToMySqlDate($('input#dateOfProduction_'+employee_idj+'.dateOfProduction_.hasDatepicker').val());
if(!datee){alert(dateMessager);e.preventPropagation();return false;}
var noOfRecords = TableData1.length;
for(i=0;i<noOfRecords;i++)
{TableData1[i]['production_date'] = datee;}
var TableData1 = $.toJSON(TableData1);
alert(JSON.stringify(TableData1));
var qurl = '<?php echo base_url();?>production_entry/submitData';
$.ajax({
url: qurl,
type: "POST",
data:"pTableData=" + TableData1,
success: function(data){
var data = $.parseJSON(data);
if(data.status == 'error')
{
alert(data.errorMessage);
}else{
alert(noOfRecords+' records sent and '+' '+data.successMessage);
$('#tr_'+employee_idj).fadeOut();
}
}
});
function storeTblValues()
{
var TableData = new Array();
$('#searchOperationTable tr').each(function(row, tr){
var x = parseInt($(tr).find("input.quantity").val());
if(x){
TableData[row]={
"employee_id" : parseInt($(tr).find("input.hiddenemployeeId").val())
, "operation_id" : parseInt($(tr).find('td:eq(0)').text())
, "quantity" : parseInt($(tr).find("input.quantity").val())
}
}
});
TableData.shift();
return TableData;
}
});
When someone enter a quantity value equal to 0 mistakenly, then the TableData1 object becomes
[ null,{"employee_id" : 3816,"operation_id":3,"quantity":10}]
and the script stops working. I want to eliminate this null. What to do?
Your check if(x) is false when a 0 is entered, so TableData[row] will not be set for that entry. Instead, set your TableData using array.push:
if(x){
TableData.push({
"employee_id" : parseInt($(tr).find("input.hiddenemployeeId").val())
, "operation_id" : parseInt($(tr).find('td:eq(0)').text())
, "quantity" : parseInt($(tr).find("input.quantity").val())
})
}
If you don't care about the index values of the array, then you can use push(value) instead of array[index]=value.
like in my example:
TableData.push({
"employee_id" : parseInt($(tr).find("input.hiddenemployeeId").val()),
"operation_id" : parseInt($(tr).find('td:eq(0)').text()),
"quantity" : parseInt($(tr).find("input.quantity").val())
});`
I have an exercise which i don´t really understand, so I hope for some help for this.
I should hardcode a simple array and the exercise tells me this:
Often, when we create our web applications, we have the need for test data. Implement a reusable nodejs module, using JavaScripts module pattern, which can provide random test data as sketched below:
var data = dataGenerator.getData(100,"fname, lname, street, city, zip");
This should return a JavaScript array (not JSON) with 100 test data on the form:
[{fname: "Bo", lname:"Hansen", street: "Lyngbyvej 26", city: "Lyngby", zip: "2800"},..]
If you call it like this:
var data = dataGenerator.getData(25,fname, lname);
it should return 25 test data as sketched below:
[{fname: "Bo", lname:"Hansen"},..]
I have some code here, but this dosen´t work yet:
var dataGenerator = (function () {
var data = [
{
fname : "Bo",
lname : "Bosen",
...
},
{
fname : "jashkjh",
lname : "jhsdkfj",
...
},
...
];
return {getData : function (count, fields) {
var result = [];
var i = 0;
var field;
var j;
fields = fields.split(/\s*,\s*/);
while (i < count && i < data.length) {
result.push({});
// Det objekt vi arbejder på lige nu er i result[i]
for (j = 0; j < fields.length; j++) {
result[i][fields[j]] = data[i][fields[j]];
}
i++;
}
return result;
}};
})();
module.exports = dataGenerator;
I do not know the data body, but could try:
var data=[{fname:"Bo",lname:"Bosen",street:"Lyngbyvej 26",city:"Lyngby",zip:"2800"},{fname:"jashkjh",lname:"jhsdkfj",street:"Fmsn 9",city:"Pra",zip:"1600"},{fname:"eeee",lname:"aaaa",street:"Eda 5",city:"Pre",zip:"3500"}];
var dataGenerator = {
getData: function(count, fieldsStr){
var result = [], fields = fieldsStr.split(/\s*,\s*/), i = 0;
while(i < count && data[i]){
var item = {};
fields.forEach(function(key){
item[key] = data[i][key]
});
result.push(item);
i++
}
return result
}
}
var results = dataGenerator.getData(2,"fname, zip");
document.write(JSON.stringify(results))
The function below should return an array of objects with this structure:
TopicFrequency = {
name: "Chemistry", //This is dependent on topic
data: [1,2,3,4,5,6,7,8,9,10,11,12] //This would be real data
};
so when I do this:
myData = this.getChartData("line");
it should return two objects:
{name : "Chemistry", data : [1,2,3,4,51,12,0,0, 2,1,41, 31]}
{name : "Math", data : [0,0,41,4,51,12,0,0, 2,1,41, 90]}
so when I do console.log(myData); it's perfect, returns exactly this.
However when I do console.log(myData[0].data) it returns all 0s, not the values. I'm not sure what this issues is known as, and my question is simple what is this problem known as?
Here is the full function. Somethings were hardcoded and other variables (notable server and queryContent) removed. Those parts worked fine, it is only when manipulated/retreiving the returned array's values that I run into problems. Note this is async. so not sure if that is also part of the problem.
getChartData: function (chartType) {
var TopicsFrequencyArray = new Array();
timePairs = this.newIntervalSet("Month");
topicList = new Array("Chemistry", "Math");//Hard coded for now
var queryCopy = {
//sensitive information
};
for (i = 0; i < topicList.length; i++) {
var TopicFrequency = {
name: null,
data: this.newFilledArray(12, 0)
};
j = 0;
TopicFrequency.name = topicList[i];
while (j < timePairs.length) {
queryCopy.filter = TopicFrequency.name;
//additional queryCopy parameter changes made here
var request = esri.request({ url: server, content: queryCopy, handleAs: "json", load: sucess, error: fail });
j = j + 1;
function sucess(response, io) {
var topicCountData = 0;
query = esri.urlToObject(io.url);
var dateString = query.query.fromDate.replace("%", " ");
dateString = dateString.replace(/-/g, "/");
dateString = dateString.split(".");
date = new Date(dateString[0]);
dojo.forEach(response.features, function (feature) {
if (feature.properties.count > 0) {
topicCountData = feature.properties.count;
}
TopicFrequency.data[date.getMonth()] = topicCountData;
});
}
function fail(error) {
j = j + 1;
alert("There was an unspecified error with this request");
console.log(error);
}
}
TopicsFrequencyArray.push(TopicFrequency);
}
},