I have a sendData.JSON.aspx page that sends data to the textfile called Print.txt.
but i want to Print only data that is selected on my web-browser page/HTML PAGE ,NOTE on that web-browser page
the DATA is selected on a TABLE . and i have a checkbox column so i want to print all selected ROWS accordingly.
Here is my code to print:
function printSelected()
{
var selecteditems = hesto.ui.getselecteditems('#scannedlabeltable');
$.each(selecteditems, function (i, item) {
$.ajax({
url: SEND_TO_TEXTFILE_PAGE
, data: "serial=" + item.id
, datatype: 'json'
, success: function (status) {
if (status.error) {
alert(status.error);
}
}
, error: hesto.ajax.errorhandler
});
});
Related
I want to get a data value from the clicked td, which opens a modal with the informations of the user.
When I select all users, everything works fine..
But when I want to search a specific user (table is not displayed until you search for a user), the modal shows not the right data..
I created a JS array with the usernames and put it in my data value. The innerHTML from the column is the first- and last name of the user.
The problem is that when I click on the name the modal shows the information from the FIRST user in my array (grouped by lastname ASC)
I'm using the DataTables plugin. Here's a short example of my drawCallback function:
"drawCallback": function(settings) {
var api = this.api();
var rows = api.rows({
page: 'current'
}).nodes();
var last = null;
api.column(0, {
page: 'current'
}).data().each(function(group, i) {
if (last !== group) {
var groupName = api.row(i).data();
$(rows).eq(i).before(
'<tr class="group"><td style="font-weight: bold;" data-value="'+groupName[0]+'" data-toggle="modal" data-target="#profileModal" class="tdPerson" colspan="1">'+group+'</td><td colspan="5"></td></tr>'
);
last = group;
}
});
}
Here's my AJAX request:
$('.table').on('click', '.tdPerson', function(event) {
id = $(this).attr('data-value');
$.ajax({
url: "getData.php",
data: {
type: "getPersonModal",
data: id
},
type: "POST",
success: function(data) {
$('#profileModalContent').html(data);
}
});
});
i have a modal form where user enters details like for an item,the modal has a select option where user can select the item category there are savings,i have no problem here.the issue is when the user want to edit some details of the item.u will require to retrieve the item.here is my issue i cant get the category saved transferred back to the select option then set is as selected.
how can i do this.//id of selected category is the one that is inserted to db.
$.get(
'../Inventory/PopulateCategory',
{},
function (data) {
$('#Category').empty();
$.each(data,
function (key, value) {
$('#Category')
.append($("<option />")
.val(value.StockCategoryId)
.html(value.StockCategory));
});
},
'json'
);
this is how i retrieve the value,am able to load input but cant get to load the correct saved item to select.
function EditCompanyRecord(_id) {
var url = "/Inventory/itemEdit?_id=" + _id;
$.ajax({
type: "GET",
url: url,
dataType: "json",
success: function (data) {
var obj = JSON.parse(data);
var currcat = obj.StockCategory;
var _vat = obj.taxcode;
$("#StockId").val(_id);
$("#Description").val(obj.description);
$('#Category').val(obj.StockCategory)
//i need to reverse and get save id as the selected category
}
});
}
The value persisted as category for the stock is the category name/title.
While the options input uses the category id for the value.
In order to have persisted category for the stock selected in the category options, you need to find the id for the persisted category for the stock in the category options. e.g.
const $objStockCategoryId = $('#Category').children().filter((i, e) =>
e.text === obj.StockCategory);
Then select the category option
$('#Category').val($objStockCategoryId.val());
However, I suggest to set a data attribute in the category options for a succinct DOM query. e.g.
$.each(data,
function (key, value) {
$('#Category')
.append(
$("<option />")
.attr('data-name', value.StockCategory)
.val(value.StockCategoryId)
.html(value.StockCategory)
);
});
const $objStockCategoryId = $('#Category')
.find(`[data-name="${obj.StockCategory}"]`);
$('#Category').val($objStockCategoryId.val());
I have the following code in my js file. When i alerted and checked the value of key, its being coming from JSON response, but when i checked my val, its shown as [object object]. So i tried using val.value, the value comes to be undefined.
FYI: I am getting the correct response from my controller through Json, i have checked it, all i want to know is how to populate text value into the dropdown.
$(document).ready(function () {
BindTitle();
});
function BindTitle() {
$.ajax({
"url": "/Admin/GetTitleList/",
"type": "get",
"dataType": "json",
"success": function (data) {
var appenddata;
$.each(data, function (key, val) {
appenddata += "<option value = '" + key + " '>" + val.text + " </option>";
});
$("#TitleId").html(appenddata);
}
});
}
Your way of building dropdown wont work on ie8
try
$.ajax({
url: "/Admin/GetTitleList/",
type: "GET"
success: function (data) {
var items = $('#id of your dropdown');
items.empty();
$.each(data, function (i, drddata) {
items.append($('<option/>', { value: drddata.Value, html: drddata.Text
});
});
},
error: function () {
}
});
I try to get several series of data from employees and get them drawed through HighCharts.
I don't know the company till the user click, so then I get trough ajax all the employees and their data (points).
I have a select box where I choose the company. Once done, I call via AJAX/jQuery the server to get data added to HighChart:
$("#company").change(function(){
$.ajax({
type: 'POST',
dataType: 'json',
url: xxxxx,
async: false,
data: { company: company},
success: function(data) {
$.each(data, function(val, text) {
alert (val);
alert (text);
chart2.addSeries({
name: val,
data: text
});
});
}
...
Data I get from the server trough Firebug is in this way:
{"Employee1":[["1356908400000","10.00"],["1359586800000","11.00"], ["1362006000000","12.00"],["1364684400000","13.45"]],"Employee2":[["1356908400000","10.00"],["1359586800000","11.00"],["1362006000000","12.00"],["1364684400000","13.45"]]}
Employee1 and Employee2 should be the series.
However when I call addseries method I get this error:
Uncaught Highcharts error #14: www.highcharts.com/errors/14
It seems data doesn't like to Highcharts.
When I debug through alerts, I get this:
alert (val)->Employee1
alert (text)=1356908400000,10.00,1359586800000,11.00,1362006000000,12.00,1364684400000,13.45
This example is working fine when I put data without ajax.
Any idea?
I've found the answer :-)
text is an array so I need another $.each to read it and format the result:
success: function(data) {
$("html").css('cursor','auto');
$.each(data, function(val, text) {
counter = 0;
$.each(text, function() {
if (counter==0) {
employee_data= "[" + this + "]";
}
else{
employee_data= employee_data + "," + "[" + this + "]";
}
counter=1
});
employee_data = "["+ + "]";
chart.addSeries({
name: val,
data: employee_data
});
});
},
I want the drop down options to reflect all the items in an array stored in a file called companyinfo.js, which i request via ajax. I call the dropDownList() when the page loads.
function dropDownList (evt) {
console.log("dropdownfired");
var companyArray = [];
$.ajax({
url : 'assets/data/companyarray.js', //this file is just ["Facbeook", "Twitter", "Klout",]
dataType: 'script',
success: function(data) {
companyArray = data;
console.log(companyArray); //returns an array of the companies
$('#companyInput1').attr('data-source', companyArray); //#companyInput1 is the input field where I want the typehead to be
console.log($('#companyInput1').attr('data-source')); //returns undefined
}
});
}
UPDATES:
function dropDownList (evt) {
console.log("dropdownfired");
var companyArray = [];
$.ajax({
url : 'assets/data/companyarray.js', //this file is just ["Facbeook", "Twitter", "Klout",]
dataType: 'script',
success: function(data) {
companyArray = data;
console.log(companyArray); // gives array of companies
$('#companyInput1').data('data-source', companyArray);
console.log($('#companyInput1').data('data-source')); // gives undefined still
}
});
}
You should not store anything besides strings as attributes on HTML nodes. For storing an array use the .data()-method jquery offers
success: function(data) {
companyArray = data;
console.log(companyArray); //returns an array of the companies
$('#companyInput1').data('data-source', companyArray); //#companyInput1 is the input field where I want the typehead to be
console.log($('#companyInput1').data('data-source')); //should work
}