Event not working in Jquery - javascript

I have this code:
this.$root.find(".thread-vote-item").click( function() {
var current_value = self.getCurrentValue();
if(current_value !== null || current_value !== '' ) {
self.enableButton(current_value);
}
self.disableButton($(this).data('label'));
$.ajax({
url: $("#base-url").val() + '/thread/submit-vote',
type: 'post',
data: {thread_id: self.thread_id, vote: current_value},
success: function(data) {
if(data) {
self.setCurrentValue(current_value);
self.triggerChangedVoteEvent();
} else {
}
}
});
return true;
});
The click event does not work
but if i change to become lik ethis
$(".thread-vote-item").click( function() {
var current_value = self.getCurrentValue();
if(current_value !== null || current_value !== '' ) {
self.enableButton(current_value);
}
self.disableButton($(this).data('label'));
$.ajax({
url: $("#base-url").val() + '/thread/submit-vote',
type: 'post',
data: {thread_id: self.thread_id, vote: current_value},
success: function(data) {
if(data) {
self.setCurrentValue(current_value);
self.triggerChangedVoteEvent();
} else {
}
}
});
return true;
});
It works. What is the difference between $(selector) and $(selector).find();
this.$root comes from another $(selector).find

Related

When I edited directly in the grid instead of the modal at the right the filter never drops but when I edit in modal and save the filter dropped

class ProductInfoDetailsViewModel {
constructor(parent, productInfoWindowId, inventoryId, productId, supplierId, store) {
this._parent = parent;
this._created = false;
this._productInfoWindowId = productInfoWindowId;
this._inventoryId = inventoryId;
this._productId = productId;
this._supplierId = supplierId;
this._store = store;
}
_getMvvmData(inventoryId, productId, supplierId) {
return new Promise(function (resolve, reject) {
$.ajax({
url: '/ProductRowInfoSite/GetInventoryControl',
data: {
'inventoryId': inventoryId,
'productId': productId,
'supplierId': supplierId,
},
dataType: 'json', // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
success: function (result) {
resolve(result);
},
error: function (jqXHR, textStatus, errorThrown) {
reject([jqXHR, textStatus, errorThrown]);
},
type: 'POST',
});
});
}
async create() {
let self = this;
let userStore = new UserStore();
//productInfoTextGrid
this._productInfoDetailsViewModel = kendo.observable({
value: {},
close: function () {
//$("#generalProductInfoWindow").data("kendoWindow").close();
//closeWindow();
},
not: function (value) {
return !this.get(value);
},
save: function (e) {
let productInfoTextGrid = $(self._productInfoWindowId + ' ' + '#productInfoTextGrid').data('kendoGrid');
/* productInfoTextGrid.saveChanges();*/
let orderUnitsGrid = $(self._productInfoWindowId + ' ' + '#orderUnitsGrid').data('kendoGrid');
let selectedRefHistProd = null;
try {
selectedRefHistProd = this.get('value.SelectedRefHistProd').ProductId;
} catch (error) {
// may be set to null and that's fine/TK.
}
var data = {
ProductId: self._productId,
InventoryId: self._inventoryId,
SupplierId: self._supplierId,
Fmean: this.get('value.Fmean'),
FMAD: this.get('value.FMAD'),
FTrend: this.get('value.FTrend'),
SelectedSeason: this.get('value.SelectedSeason').SeasonId,
MinQuantity: this.get('value.MinQuantity'),
SelectedOrderUnitNo: this.get('value.SelectedOrderUnit').UnitNo,
LeadTime: this.get('value.LeadTime'),
LeadTimeDeviation: this.get('value.LeadTimeDeviation'),
StockKeepInterest: this.get('value.StockKeepInterest'),
MaxLevel: this.get('value.MaxLevel'),
MinLevel: this.get('value.MinLevel'),
OrderQuantity: this.get('value.OrderQuantity'),
ReorderLevel: this.get('value.ReorderLevel'),
EnableManualSetRAndQ: this.get('value.EnableManualSetRAndQ'),
ForecastError: this.get('value.ForecastError'),
SelectedHistoryProductId: selectedRefHistProd,
};
var dataString = JSON.stringify(data);
$.ajax({
url: '/ProductRowInfoSite/SaveParameters',
data: {
data: dataString,
},
dataType: 'json',
// "jsonp" is required for cross-domain requests; use "json" for same-domain requests
success: function (result) {
// notify the data source that the request succeeded
//options.success(result);
self._store.dispatch({ type: ActionProductInfoWindow.Saving });
self._parent.refreshParentGrids();
},
error: function (result) {
displayAjaxError(result);
},
type: 'POST',
});
let userStore = new UserStore();
let finishSaved = userStore.translatedString('SOLOSupplier.ProductInfoWindows.FinishSaved');
displaySuccess(finishSaved);
productInfoTextGrid.saveChanges();
orderUnitsGrid.saveChanges();
},
recalc: function () {
var validator = $(self._productInfoWindowId).kendoValidator().data('kendoValidator');
var a = validator.validate();
},
products: new kendo.data.DataSource({
type: 'json',
serverFiltering: true,
pageSize: 100,
transport: {
read: function (options) {
$.ajax({
url: '/ProductRowInfoSite/GetProductInventoryList',
data:
{
'inventoryId': self._inventoryId,
'productId': self._productId,
'data': options.data,
},
//"filter": filter
dataType: 'json', // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
success: function (result) {
// notify the data source that the request succeeded
options.success(result.HistProducts);
},
error: function (result) {
// notify the data source that the request failed
options.error(result);
},
type: 'POST',
});
},
parameterMap: function (data, type) {
return kendo.stringify($.extend({ 'text': $(data.filter.filters).get(0).value }, data));
},
},
}),
isEnabled: true,
onValidate: function (e) {
console.log('onValidate');
let maxLevel = this.get('value.MaxLevel');
let minLevel = this.get('value.MinLevel');
let userStore = new UserStore();
let validationErrorMessage = userStore.translatedString('uctrlSupplierWeb.MaxLevelMinLevelWarning');
let validator = $(self._productInfoWindowId).kendoValidator({
messages: {
custom: validationErrorMessage,
},
rules: {
custom: function (input) {
if (input.is('[name=minLevelParameter]') && input.val() === '') {
return true;
} else if (input.is('[name=minLevelParameter]') && input.val() !== '' && maxLevel !== null) {
return maxLevel > minLevel;
}
if (input.is('[name=maxLevelParameter]') && input.val() === '') {
return true;
} else if (input.is('[name=maxLevelParameter]') && input.val() !== '' && minLevel !== null) {
return maxLevel > minLevel;
} else {
return true;
}
},
},
},
).data('kendoValidator');
if (validator.validate() === true) {
self._store.dispatch({ type: ActionProductInfoWindow.Changing });
} else {
self._store.dispatch({ type: ActionProductInfoWindow.Cancelling });
}
},
});
kendo.bind($(self._productInfoWindowId + ' ' + '#tabInventoryControl'), self._productInfoDetailsViewModel);
try {
let result = await self._getMvvmData(self._inventoryId, self._productId, self._supplierId);
self._productInfoDetailsViewModel.products.read();
self._productInfoDetailsViewModel.set('value', result);
if (result.UnitsOnOrderAfterLeadtime === true) {
if ($(self._productInfoWindowId + ' ' + '#valueUnitsOnOrder').data('kendoNumericTextBox')) {
let widget = $(self._productInfoWindowId + ' ' + '#valueUnitsOnOrder').data('kendoNumericTextBox');
widget.wrapper.find('input').addClass('lightRed');
}
}
if ($(self._productInfoWindowId + ' ' + '#minLevelParameterId').data('kendoNumericTextBox')) {
$(self._productInfoWindowId + ' ' + '#minLevelParameterId')
.data('kendoNumericTextBox')
.min(result.MinLevelDefault);
}
if ($(self._productInfoWindowId + ' ' + '#maxLevelParameterId').data('kendoNumericTextBox')) {
$(self._productInfoWindowId + ' ' + '#maxLevelParameterId')
.data('kendoNumericTextBox')
.min(result.MinLevelDefault);
}
var validator = $(self._productInfoWindowId).kendoValidator().data('kendoValidator');
validator.validate();
let element = $(self._productInfoWindowId);
window.kendo.ui.progress(element, false);
} catch ([jqXHR, textStatus, errorThrown]) {
displayAjaxError(jqXHR, textStatus, errorThrown);
productInfoDetailsViewModel.set('value', []);
window.kendo.ui.progress(element, false);
}
}
}
Saving edits in product info modal deletes used filters on products grid
if (productNo === null) {
let newFilter = await self._getFilterOnlyFromLocalStorage();
let totalFilter = $(self._gridId).data("kendoGrid").dataSource.filter();
totalFilter.filters.push.apply(totalFilter.filters, newFilter.filters);
$(self._gridId).data("kendoGrid").dataSource.filter(newFilter);
self._setPredefinedFilterButton(self);
}
}

jquery stop form submisson on false condition

I am validating a duplicate value through ajax. if a duplicate is found then it alerts with an error but does not stop on submission.
$(function() {
$("#admno").on("keyup", function(e) {
e.preventDefault();
var oadmno = $("#oadmno").val();
var admno = $("#admno").val();
if (oadmno != admno) {
$.ajax({
type: "post",
url: "chkduplicateadmino.php",
data: $("#admno").serialize(),
success: function(data) {
if (data > 0) {
$("#admno")
.closest(".form-group")
.addClass("has-warning");
toastr.error("", "Duplicate admission no found", {
positionClass: "toast-bottom-right",
preventDuplicates: true
});
$("#admno").focus();
return false;
} else {
return true;
}
}
});
}
});
});

Ajax callback is firing after function call

Hi Have a ajax call in a function thats called on date input change event to check if a date is already in use for User. the success in the Ajax call fires after the click function is finished.
How do I get the success results and continue on with the #datepicker change funtion as I need the json results for rest of function.
controller
public ActionResult IsDateAvailable(DateTime date, int Id) {
var dateAvailable = !(_context.Trading.Any(t => t.uId == Id && t.TradingDate == date));
if (!(dateAvailable)) {
return Json(new {
status = false, msg = "This date already exists."
});
}
return Json(new {
status = true
});
}
JavaScript
$(document).ready(function() {
var message;
var isDateValid;
function CheckDate(para) {
var dateValid;
var mesg;
return $.ajax({
url: '#Url.Action("IsDateAvailable", "Trading")',
type: "GET",
data: para,
dataType: "json",
success: function(data) {
if (!(data.status)) {
message = data.msg;
} else {
isDateValid = true;
}
},
error: function(xhr, httpStatusMessage) {
alert(xhr + httpStatusMessage);
}
});
}
$("#datePicker").change(function() {
$("#alert").css({
'display': 'none'
});
if (Id == 0) {
$("#alert").attr('class', 'alert alert-danger');
$("#alert").text('Please select a User.');
$("#alert").show();
return false;
}
var date = $(this).val();
var para = {
date: date,
Id: Id
};
CheckDate(para);
if (isDateValid) {
$("#btnAdd").show();
} else {
$("#btnAdd").css({
'display': 'none'
});
$("#alert").attr('class', 'alert alert-danger');
$("#alert").text(message);
$("#alert").show();
}
});
});
You should turn to being asynchronous. change your code to match with these:
.
.
.
function CheckDate(para) {
return new Promise((resolve, reject) => {
return $.ajax({
url: '#Url.Action("IsDateAvailable", "Trading")',
type: "GET",
data: para,
dataType: "json",
success: function(data) {
if (!(data.status)) {
message = data.msg;
} else {
isDateValid = true;
}
resolve();
},
error: function(xhr, httpStatusMessage) {
alert(xhr + httpStatusMessage);
reject();
}
});
}
.
.
.
checkDate(para).then(res => {
if (isDateValid) {
$("#btnAdd").show();
} else {
$("#btnAdd").css({
'display': 'none'
});
$("#alert").attr('class', 'alert alert-danger');
$("#alert").text(message);
$("#alert").show();
}
}).catch(err => { /* do something */ });
You just need to set async: false inside your ajax request. You can also remove the word return from the CheckDate, because of it's redundant:
function CheckDate(para) {
var dateValid;
var mesg;
$.ajax({
url: '#Url.Action("IsDateAvailable", "Trading")',
async: false,
type: "GET",
data: para,
dataType: "json",
success: function(data) {
if (!(data.status)) {
message = data.msg;
} else {
isDateValid = true;
}
},
error: function(xhr, httpStatusMessage) {
alert(xhr + httpStatusMessage);
}
});
}

javascript works on localhost but fails on hosting server

When i click on add-to-basket button i see an error which appears in my browser console saying :
Here is my basket.js file :
$(document).ready(function() {
initBinds();
function initBinds() {
if ($('.remove_basket').length > 0) {
$('.remove_basket').bind('click', removeFromBasket);
}
if ($('.update_basket').length > 0) {
$('.update_basket').bind('click', updateBasket);
}
if ($('.fld_qty').length > 0) {
$('.fld_qty').bind('keypress', function(e) {
var code = e.keyCode ? e.keyCode : e.which;
if (code == 13) {
updateBasket();
}
});
}
}
function removeFromBasket() {
var item = $(this).attr('rel');
$.ajax({
type: 'POST',
url: '/home/u919084925/public_html/mod/basket_remove.php',
dataType: 'html',
data: ({ id: item }),
success: function() {
refreshBigBasket();
refreshSmallBasket();
},
error: function() {
alert('An error has occurred');
}
});
}
function refreshSmallBasket() {
$.ajax({
url: '/home/u919084925/public_html/mod/basket_small_refresh.php',
dataType: 'json',
success: function(data) {
$.each(data, function(k, v) {
$("#basket_left ." + k + " span").text(v);
});
},
error: function(data) {
alert("An error has occurred");
}
});
}
function refreshBigBasket() {
$.ajax({
url: '/home/u919084925/public_html/mod/basket_view.php',
dataType: 'html',
success: function(data) {
$('#big_basket').html(data);
initBinds();
},
error: function(data) {
alert('An error has occurred');
}
});
}
if ($(".add_to_basket").length > 0) {
$(".add_to_basket").click(function() {
var trigger = $(this);
var param = trigger.attr("rel");
var item = param.split("_");
$.ajax({
type: 'POST',
url: '/home/u919084925/public_html/mod/basket.php',
dataType: 'json',
data: ({ id : item[0], job : item[1] }),
success: function(data) {
var new_id = item[0] + '_' + data.job;
if (data.job != item[1]) {
if (data.job == 0) {
trigger.attr("rel", new_id);
trigger.text("Remove from basket");
trigger.addClass("red");
} else {
trigger.attr("rel", new_id);
trigger.text("Add to basket");
trigger.removeClass("red");
}
refreshSmallBasket();
}
},
error: function(data) {
alert("An error has occurred");
}
});
return false;
});
}
function updateBasket() {
$('#frm_basket :input').each(function() {
var sid = $(this).attr('id').split('-');
var val = $(this).val();
$.ajax({
type: 'POST',
url: '/home/u919084925/public_html/mod/basket_qty.php',
data: ({ id: sid[1], qty: val }),
success: function() {
refreshSmallBasket();
refreshBigBasket();
},
error: function() {
alert('An error has occurred');
}
});
});
}
// proceed to paypal
if ($('.paypal').length > 0) {
$('.paypal').click(function() {
var token = $(this).attr('id');
var image = "<div style=\"text-align:center\">";
image = image + "<img src=\"/images/loadinfo.net.gif\"";
image = image + " alt=\"Proceeding to PayPal\" />";
image = image + "<br />Please wait while we are redirecting you to PayPal...";
image = image + "</div><div id=\"frm_pp\"></div>";
$('#big_basket').fadeOut(200, function() {
$(this).html(image).fadeIn(200, function() {
send2PP(token);
});
});
});
}
function send2PP(token) {
$.ajax({
type: 'POST',
url: '/mod/paypal.php',
data: ({ token : token }),
dataType: 'html',
success: function(data) {
$('#frm_pp').html(data);
// submit form automatically
$('#frm_paypal').submit();
},
error: function() {
alert('An error has occurred');
}
});
});
I tried to resolve it but couldn't find a proper solution.
Help me with this, I cannot understand the cause of this error.
This is mainly due to Rules of Origins (CORS), for some reason the javascript(browser) sees the request as not residing in the same server. And the reason for that, I believe, is because /home/u919084925/public_html/mod/basket.php is not seen as a valid url on the server, it should start with http://{hostname}/{path}.
It looks like your ajax url is totally wrong and the browser interpret that is cross origin ajax request. Please simply check in browser's address bar if your ajax provided urls are valid.

UI Unresponsive when we jquery ajax abort called

I am doing a four API calls(for twitter,facebook,instagram,youtube) on selecting brand name and get data and set the response to different div.
When if i select first brand say "ford" and request made by using ajax asynchronous call, on between request if i select other brand,then previous made request is aborted and second one get processed.
First Ajax calls is aborted and second request was run but between abort process,my dropdown box get unresponsive until all request get aborted.
Sample code :
$(document).ready(function ()
{
var cblcurrentRequest = null;
var currentRequest = null;
var twcurrentRequest = null;
var fbcurrentRequest = null;
var igcurrentRequest = null;
var ytcurrentRequest = null;
var firsttwcurrentRequest = null;
var firstfbcurrentRequest = null;
var firstigcurrentRequest = null;
var firstytcurrentRequest = null;
load_session();//load access key on session
$('#brands').prop('disabled', 'disabled');
$('#selcategory').change(function () {
$('.loader_cmn').show();
$("#brands").select2("val", null);
$('#brands').append('<option value=" ">Select Brand Name</option>');
$('#brands').prop('disabled', true);
var categoryID = this.value;
if (categoryID != "") {
currentRequest = $.ajax({url: baseurl + 'admin/Adminhome/getCategoryListByIdWithLogin/' + categoryID, type: 'post', data: '',
beforeSend: function () {
var msg = "<center><b>Please select brand</b></center>";
$('#tw').html(msg);
$('#fb').html(msg);
$('#inst').html(msg);
$('#yt').html(msg);
hide_loader();
if (currentRequest != null) {
currentRequest.abort();
}
if (twcurrentRequest != null) {
twcurrentRequest.abort();
}
if (fbcurrentRequest != null) {
fbcurrentRequest.abort();
}
if (igcurrentRequest != null) {
igcurrentRequest.abort();
}
if (ytcurrentRequest != null) {
ytcurrentRequest.abort();
}
if (firsttwcurrentRequest != null) {
firsttwcurrentRequest.abort();
}
if (firstfbcurrentRequest != null) {
firstfbcurrentRequest.abort();
}
if (firstigcurrentRequest != null) {
firstigcurrentRequest.abort();
}
if (firstytcurrentRequest != null) {
firstytcurrentRequest.abort();
}
}
}).done(function (res)
{
$("#brands").empty();
$('#brands').append('<option value="" selected="">Select Brand Name</option>');
var obj = JSON.parse(res);
$.each(obj, function (i, item) {
$('#brands').append('<option value="' + obj[i].BrandID + '">' + obj[i].BrandName + '</option>');
});
$('.loader_cmn').hide();
$('#brands').prop('disabled', false);
}).fail(function (res) {
});
}
});
$('#display_alert').show();
function load_session() {
$.ajax({url: baseurl + 'Login/set_accesskeys', type: 'post', async: false, cache: true, data: ''}).done(function (res)
{
setTimeout(2000);
}).fail(function (res) {
});
}
var msg = "<center><b>Please select brand</b></center>";
if ($("#brands").val() === "") {
$('#tw').html(msg);
$('#fb').html(msg);
$('#inst').html(msg);
$('#yt').html(msg);
$('#yelp').html(msg);
} else {
var brand_id = $.trim($("#brands").val());
load_social_feeds(brand_id);
}
$("#brands").change(function () {
$(window).scrollTop(0);
var brand_id = $.trim(this.value);
load_social_feeds(brand_id);
});
function hide_loader()
{
$('#loader_tw').hide();
$('#loader_fb').hide();
$('#loader_inst').hide();
$('#loader_yt').hide();
}
function getChannelBrandlistJson(brand_id)
{
var channelBrandList;
var facebookBrandName;
var twitterBrandName;
var youtubeBrandName;
var instagramBrandName;
var yelpBrandName;
cblcurrentRequest = $.ajax({url: baseurl + 'Login/getChannelBrand/' + brand_id, type: 'post', async: false, cache: true, data: '',
beforeSend: function () {
if (cblcurrentRequest != null) {
cblcurrentRequest.abort();
}
if (firsttwcurrentRequest != null) {
firsttwcurrentRequest.abort();
}
if (firstfbcurrentRequest != null) {
firstfbcurrentRequest.abort();
}
if (firstigcurrentRequest != null) {
firstigcurrentRequest.abort();
}
if (firstytcurrentRequest != null) {
firstytcurrentRequest.abort();
}
if (twcurrentRequest != null) {
twcurrentRequest.abort();
}
if (fbcurrentRequest != null) {
fbcurrentRequest.abort();
}
if (igcurrentRequest != null) {
igcurrentRequest.abort();
}
if (ytcurrentRequest != null) {
ytcurrentRequest.abort();
}
}
}).done(function (res)
{
channelBrandList = JSON.parse(res);
facebookBrandName = channelBrandList['FacebookChannel'];
twitterBrandName = channelBrandList['TwitterChannel'];
youtubeBrandName = channelBrandList['YoutubeChannel'];
instagramBrandName = channelBrandList['InstagramChannel'];
YelpBrandName = channelBrandList['YelpChannel'];
$('#facebookchannel').val(facebookBrandName);
console.log(facebookBrandName);
$('#twitterchannel').val(twitterBrandName);
console.log(twitterBrandName);
$('#youtubechannel').val(youtubeBrandName);
console.log(youtubeBrandName);
$('#instagramchannel').val(instagramBrandName);
console.log(instagramBrandName);
$('#yelpchannel').val(YelpBrandName);
console.log(yelpBrandName);
}).fail(function (res) {
});
}
function Twfeed(brand_name)
{
var indexCount = 2;//used to calls the all three month post
$('#twContainer').scrollTop(0);
$('#twContainer').perfectScrollbar('update');
loader_show();
// setTimeout(function wait() {
twcurrentRequest = $.ajax({url: baseurl + 'Twfeed/get_Twfeed/' + brand_name + '/' + indexCount, type: 'post', data: '',
beforeSend: function () {
if (twcurrentRequest != null) {
twcurrentRequest.abort();
}
}
}).done(function (res)
{
if (res != null && res.trim() != '')
{
setcontent(res);
}
}).fail(function (res) {
});
//}, 1000);
}
function FirstTwfeed(brand_name)
{
var indexCount = 1; //used to calls the first three post
$('#twContainer').scrollTop(0);
$('#twContainer').perfectScrollbar('update');
loader_show();
// setTimeout(function wait() {
firsttwcurrentRequest = $.ajax({url: baseurl + 'Twfeed/get_Twfeed/' + brand_name + '/' + indexCount, type: 'post', data: ''}).done(function (res)
{
if (res != null && res.trim() != '')
{
setcontent(res);
Twfeed(brand_name);
}
}).fail(function (res) {
});
// }, 1000);
}
function Fbfeed(brand_name)
{
// load_session();
var indexCount = 2;
$('#fbContainer').scrollTop(0);
$('#fbContainer').perfectScrollbar('update');
$('#loader_fb').show();
//setTimeout(function wait() {
fbcurrentRequest = $.ajax({url: baseurl + 'Fbfeed/get_Fbfeed/' + brand_name + '/' + indexCount, type: 'post', data: '',
beforeSend: function () {
if (fbcurrentRequest != null) {
fbcurrentRequest.abort();
}
}
}).done(function (res)
{
if (res != null && res.trim() != '')
{
$('#fb').html(res);
$('#loader_fb').hide();
}
}).fail(function (res) {
});
//}, 1000);
}
function FirstFbfeed(brand_name)
{
// load_session();
var indexCount = 1;
$('#fbContainer').scrollTop(0);
$('#fbContainer').perfectScrollbar('update');
$('#loader_fb').show();
//setTimeout(function wait() {
firstfbcurrentRequest = $.ajax({url: baseurl + 'Fbfeed/get_Fbfeed/' + brand_name + '/' + indexCount, type: 'post', data: '',
}).done(function (res)
{
if (res != null && res.trim() != '')
{
$('#fb').html(res);
$('#loader_fb').hide();
Fbfeed(brand_name);
}
}).fail(function (res) {
});
//}, 1000);
}
function Instfeed(brand_name)
{
//load_session();
var indexCount = 2;
$('#instaContainer').scrollTop(0);
$('#instaContainer').perfectScrollbar('update');
$('#loader_inst').show();
// setTimeout(function wait() {
igcurrentRequest = $.ajax({url: baseurl + 'Igfeed/get_Igfeed/' + brand_name + '/' + indexCount, type: 'post', data: '',
beforeSend: function () {
if (igcurrentRequest != null) {
igcurrentRequest.abort();
}
}
}).done(function (res)
{
if (res != null && res.trim() != '')
{
$('#inst').html(res);
$('#loader_inst').hide();
}
}).fail(function (res) {
});
//}, 1000);
}
function FirstInstfeed(brand_name)
{
//load_session();
var indexCount = 1;
$('#instaContainer').scrollTop(0);
$('#instaContainer').perfectScrollbar('update');
$('#loader_inst').show();
// setTimeout(function wait() {
firstigcurrentRequest = $.ajax({url: baseurl + 'Igfeed/get_Igfeed/' + brand_name + '/' + indexCount, type: 'post', data: '',
}).done(function (res)
{
if (res != null && res.trim() != '')
{
$('#inst').html(res);
$('#loader_inst').hide();
Instfeed(brand_name);
}
}).fail(function (res) {
});
//}, 1000);
}
function Ytfeed(brand_name)
{
//load_session();
var indexCount = 2;
$('#ytContainer').scrollTop(0);
$('#ytContainer').perfectScrollbar('update');
$('#loader_yt').show();
//setTimeout(function wait() {
ytcurrentRequest = $.ajax({url: baseurl + 'Ytfeed/get_Ytfeed/' + brand_name + '/' + indexCount, type: 'post', data: '',
beforeSend: function () {
if (ytcurrentRequest != null) {
ytcurrentRequest.abort();
}
}
}).done(function (res)
{
if (res != null && res.trim() != '')
{
$('#yt').html(res);
$('#loader_yt').hide();
}
}).fail(function (res) {
});
// }, 1000);
}
function FirstYtfeed(brand_name)
{
//load_session();
var indexCount = 1;
$('#ytContainer').scrollTop(0);
$('#ytContainer').perfectScrollbar('update');
$('#loader_yt').show();
//setTimeout(function wait() {
firstytcurrentRequest = $.ajax({url: baseurl + 'Ytfeed/get_Ytfeed/' + brand_name + '/' + indexCount, type: 'post', data: '',
}).done(function (res)
{
if (res != null && res.trim() != '')
{
$('#yt').html(res);
$('#loader_yt').hide();
Ytfeed(brand_name);
}
}).fail(function (res) {
});
// }, 1000);
}
function setcontent(res) {
$('#tw').html(res);
loader_hide();
}
function loader_show() {
$('#loader_tw').show();
}
function loader_hide() {
$('#loader_tw').hide();
}
function load_social_feeds(brand_id) {
//load_session();
getChannelBrandlistJson(brand_id);
//load_session();
//setTimeout(function wait() {
$('#tw').html("");
$('#fb').html("");
$('#inst').html("");
$('#yt').html("");
$('#yelp').html("");
//var brand_name = $.trim($("#brands").val());
//alert('load method');
if (brand_id !== "") {
$(".chanel input[type=checkbox]:checked").each(function ()
{
//alert("Id: " + $(this).attr("id") + " Value: " + $(this).val() + " Checked: " + $(this).is(":checked"));
$exp = parseInt($(this).val());
switch ($exp) {
case 1:
$('#twsection').show();
var twitterBrandName = $('#twitterchannel').val();
console.log('twitterBrandName-' + twitterBrandName);
FirstTwfeed(twitterBrandName);
// Twfeed(twitterBrandName); // Load Twitter
break;
case 2:
$('#fbsection').show();
var facebookBrandName = $('#facebookchannel').val();
console.log('facebookBrandName-' + facebookBrandName);
FirstFbfeed(facebookBrandName);
// Fbfeed(facebookBrandName); // Load Facebook
break;
case 3:
$('#instsection').show();
var instagramBrandName = $('#instagramchannel').val();
console.log('instagramBrandName-' + instagramBrandName);
FirstInstfeed(instagramBrandName); // Load Instagram
//Instfeed(instagramBrandName); // Load Instagram
break;
case 4:
$('#ytsection').show();
var youtubeBrandName = $('#youtubechannel').val();
console.log('youtubeBrandName-' + youtubeBrandName);
FirstYtfeed(youtubeBrandName); //Load Youtube
//Ytfeed(youtubeBrandName); //Load Youtube
break;
}
});
} else {
$('#tw').html(msg);
$('#fb').html(msg);
$('#inst').html(msg);
$('#yt').html(msg);
$('#yelp').html(msg);
}
}
});
I am using Codeigniter framework for server script.ajax call request to my controller and controller all required API Libraries and send back HTML response back to ajax.
Please suggest,if i am missing anything.
Thanks,

Categories

Resources