qtip plugin doesn't work with jquery jtemplates plugin - json

I'm using Ajax to load data.
With help of jQuery jTemplates I load data within Container. I need to apply jqtip plugin to images withing Container, but for some reason it's not working. if it outside works fine.
Any idea why it's not working? maybe give me an idea how I can debug it?
Here is my code
$.ajax({
type: "POST",
url: "/json/default.aspx/loaditems",
data: "{'parameter':'" + parameter + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
ApplyTemplate(msg);
}
});
function ApplyTemplate(msg) {
$('#Container').setTemplateURL('/scripts/template.htm', null, { filter_data: true });
$('#Container').processTemplate(msg);
}
<div id="Container">
</div>
here is content of my template.htm page
{#foreach $T.d as post}
<div class="image_wrap" style="float: left;">
<a href="{$T.post.url}">
<img width="175" src="{$T.post.profimage}" title="test" /></a>
</div>
{#/for}
here is qtip code
<script type="text/javascript">
$(function () {
$('.image_wrap img[title]').qtip({
position: {
corner: {
target: 'topMiddle',
tooltip: 'bottomMiddle'
}
},
style: {
name: 'cream',
padding: '7px 13px',
color: '#350608',
width: {
max: 250,
min: 0
},
tip: true
}
});
});
</script>

You're running your qtip logic on $(document).ready(). The problem is that because you're loading new markup after the page has loaded, the qtip logic doesn't apply to it.
Try wrapping your qtip logic inside a function, then call the function after you run your AJAX call.
Something like this:
function InitQtip() {
$('.image_wrap img[title]').qtip({
position: {
corner: {
target: 'topMiddle',
tooltip: 'bottomMiddle'
}
},
style: {
name: 'cream',
padding: '7px 13px',
color: '#350608',
width: {
max: 250,
min: 0
},
tip: true
}
});
}
// This will take care of items loaded with the page.
$(function () {
InitQtip();
}
// This will take care of new items.
$.ajax({
type: "POST",
url: "/json/default.aspx/loaditems",
data: "{'parameter':'" + parameter + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
ApplyTemplate(msg);
InitQtip();
}
});

Related

Add a loading spinner on HTML until it receives the required data

My Node API returns a JSON object, the object is being displayed on HTML table. However, my Node app takes some time to process and return the data. So till the time data has being retrieved I want a spinner to load on the page.
$(document).ready(function() {
$("#table1").hide();
$("#myButton").click(function() {
$("#myButton").hide();
$("#table1").show();
$.ajax({
url: "http://localhost:8090/api/route1",
type: 'POST',
data: {
data1: str1,
data2: str2
},
dataType: 'json',
success: function(res) {
console.log(res);
console.log("Result1", res.result1);
console.log("Result2", res.result2);
$('#td1').append(res.result1);
$('#td2').append(res.result2);
}
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="spinner" id="loadingBtn">
Loading...
</span>
<table class="table" id="table1">
<tbody>
<tr>
<td id="td1"></td>
</tr>
<tr>
<td id="td2"></td>
</tr>
</tbody>
</table>
How and where do I put the spinner id so that it is only displayed until the data is fully rendered onto the HTML table.
$(document).ready(function() {
$("#table1").hide();
$("#myButton").click(function() {
$("#myButton").hide();
$("#table1").show();
$.ajax({
url: "https://www.mocky.io/v2/5ec78da22f0000640042721f",
type: 'GET',
dataType: 'json',
success: function(res) {
console.log(res);
console.log("Result1", res.result1);
console.log("Result2", res.result2);
$('#td1').append(res.result1);
$('#td2').append(res.result2);
},
beforeSend: function() {
$("#loadingBtn").show();
},
complete: function() {
$("#loadingBtn").hide();
}
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="spinner" id="loadingBtn" style="display:none;">
Loading...
</span>
<button id="myButton">Press</button>
<table class="table" id="table1">
<tbody>
<tr>
<td id="td1"></td>
</tr>
<tr>
<td id="td2"></td>
</tr>
</tbody>
</table>
You can just add the loading spinner on loading and done. Show the spinner on call, and just hide it when the call is done. like so:
$.ajax({
type: 'POST',
success: function(res){
console.log(res);
}
}).done(function() {
setTimeout(function(){
$(".spinner").fadeOut(300);
},500);
});
take a look at this codepen:
https://codepen.io/yic666kr/pen/mxmvbV
It depends on your structure where you have it placed but I'll go with what you have put here. You have it visible when you start loading and hide it once data is loaded from your ajax.
$(document).ready(function() {
$("#table1").hide();
$("#myButton").click(function() {
$("#myButton").hide();
$("#table1").show();
// show the loader when you click the button
$('#loadingBtn').addClass('spinner--is-active')
$.ajax({
url: "http://localhost:8090/api/route1",
type: 'POST',
data: {
data1: str1,
data2: str2
},
dataType: 'json',
success: function(res) {
console.log(res);
console.log("Result1", res.result1);
console.log("Result2", res.result2);
$('#td1').append(res.result1);
$('#td2').append(res.result2);
// hide the loader
$('#loadingBtn').removeClass('spinner--is-active')
}
});
});
});
.spinner {
display: none;
}
.spinner--is-active {
display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="spinner" id="loadingBtn">
Loading...
</span>
<table class="table" id="table1">
<tbody>
<tr>
<td id="td1"></td>
</tr>
<tr>
<td id="td2"></td>
</tr>
</tbody>
</table>
Just show your spinner in beforeSend of ajax function and hide it after data is loaded under success function.
$.ajax({
url: "http://localhost:8090/api/route1",
type: 'POST',
data: {
data1: str1,
data2: str2
},
dataType: 'json',
beforeSend: function() {
$("#loadingBtn").show();//show spinner
},
success: function(res) {
console.log(res);
console.log("Result1", res.result1);
console.log("Result2", res.result2);
$('#td1').append(res.result1);
$('#td2').append(res.result2);
$("#loadingBtn").hide();//hide spinner
}
});

Autocomplete (JqueryUI) returning blank

I'm doing assignment, and essentially what I would like to do it have an autocomplete on the input box so the user can select a 'Starter' and 'Main' from a JSON file. When inputting characters, a dropdown list is displayed, but it is not populated with values.
The JSON file (spanish.php) is:
([{"course":"starter","name":"Chorizo Sausage Rolls","price":"5.99"},{"course":"starter","name":"Sardines in Lemon Sauce","price":"6.99"},{"course":"starter","name":"Spanish Tortilla","price":"5.99"},{"course":"starter","name":"Escabeche","price":"4.99"},{"course":"main","name":"Seafood Paella","price":"13.99"},{"course":"main","name":"Albondigas Soup","price":"9.99"},{"course":"main","name":"Linguine with Mussels","price":"13.99"},{"course":"main","name":"Spanish Rice with Shrimp","price":"11.99"},{"course":"main","name":"Roasted Red Pepper Salad","price":"8.99"},{"course":"main","name":"Chorizo Fritatta","price":"10.99"},{"course":"main","name":"Lamb Meatballs","price":"12.99"}]);
Here is my code:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script type="text/javascript">
$( function() {
$( "#starter" ).autocomplete({
source: function( request, response ) {
$.ajax( {
url: "http://learn.cf.ac.uk/webstudent/sem5tl/javascript/assignments/spanish.php",
dataType: "jsonp",
data: {
term: request.term
},
success: function( data ) {
response( data );
}
} );
},
minLength: 2,
} );
} );
</script>
And the HTML:
<label for="starter">Choose starter</label>
<input type="text" name="starter" id="starter"><br>
<label for="main">Choose main</label>
<input type="text" name="main" id="main"><br>
As I said, the list is returning nothing when 2+ digits are entered. Do I need to ask for it just starters? Am I goin about this correctly? I will be asking the user to choose a starter and main, then submitting the form.
Thanks.
I'm giving here a solution for auto-completing the starter menu. Hope that you can do the same for main menu searching. Or comment in this answer, if you're facing any problem implementing this.
<!doctype html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
var starterSearchData;
$(function() {
$.ajax({
url: "http://learn.cf.ac.uk/webstudent/sem5tl/javascript/assignments/spanish.php",
dataType: "jsonp",
async: false,
success: function(data) {
starterSearchData = $.map(data, function(item) {
if (item.course == "starter")
return item.name;
});
EnableAutoComplete();
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
function EnableAutoComplete() {
$("#starter").autocomplete({
source: starterSearchData,
minLength: 2,
delay: 100
});
}
});
</script>
</head>
<body>
<label for="starter">Choose starter</label>
<input type="text" name="starter" id="starter">
</body>
</html>

Microsoft Azure with AngularJS - Data not being displayed in chart

I am able to view data locally, however when I open the Windows Azure cloud service application, there is no longer Json data being passed into my chart (http://dashboardexample.cloudapp.net/Home/Product). I get a message in the Console saying "Controller names should start with an uppercase character and end with the suffix Controller. For example: UserController.
The best practice for module names is to use lowerCamelCase. Check the name of "dx"." Not sure what is causing this issue. Any thoughts?
AngularJS
var app = angular.module('customCharts', ['dx']);
app.controller("ChartController", function ($scope, $http, $q) {
$scope.productSettings = {
dataSource: new DevExpress.data.DataSource({
load: function () {
var def = $.Deferred();
$http({
method: 'GET',
url: 'http://localhost:53640/Home/PostChart'
}).success(function (data) {
def.resolve(data);
});
return def.promise();
}
}),
series: {
title: 'Displays Product Costs for items in our Database',
argumentType: String,
argumentField: "Name",
valueField: "Cost",
type: "bar",
color: '#008B8B'
},
commonAxisSettings: {
visible: true,
color: 'black',
width: 2
},
argumentAxis: {
title: 'Items in Product Store Database'
},
valueAxis: {
title: 'Dollor Amount'
}
}
})
HTML
<script type="text/javascript" src="~/Scripts/angular.js"></script>
<script type="text/javascript" src="~/Scripts/angular-sanitize.js"></script>
<script type="text/javascript" src="~/Scripts/globalize/globalize.js"></script>
<script type="text/javascript" src="~/Scripts/dx.chartjs.js"></script>
#Scripts.Render("~/Scripts/ChartDesign.js")
<div ng-app="customCharts">
<div ng-controller="ChartController">
<div dx-chart="productSettings"></div>
</div>
</div>
As GauravMantri mentioned, you need to reference the name and location of your controller function. Ex: I had to reference /Home/PostChart in my dataSource url. this solved the issue.
AngularJS
var app = angular.module('customCharts', ['dx']);
app.controller("ChartController", function ($scope, $http, $q) {
$scope.productSettings = {
dataSource: new DevExpress.data.DataSource({
load: function () {
var def = $.Deferred();
$http({
method: 'GET',
url: '/Home/PostChart'
}).success(function (data) {
def.resolve(data);
});
return def.promise();
}
}),
series: {
title: 'Displays Product Costs for items in our Database',
argumentType: String,
argumentField: "Name",
valueField: "Cost",
type: "bar",
color: '#008B8B'
},
commonAxisSettings: {
visible: true,
color: 'black',
width: 2
},
argumentAxis: {
title: 'Items in Product Store Database'
},
valueAxis: {
title: 'Dollor Amount'
}
}
})

kendoMobileListView - Dynamic databinding with jSon

http://demos.telerik.com/kendo-ui/mobile/listview/pull-with-endless.html refering this demo we are creating kenolistview for our mobile application.
we are getting data form webapi in jSon, whend we try to bind data with list view it's giving errors we tried three methods but all are not working, please find code bellow and error bellow code.
<body>
<div data-role="view" data-init="mobileListViewPullWithEndless" data-title="Pull to refresh">
<header data-role="header">
<div data-role="navbar">
<span data-role="view-title"></span>
<a data-align="left" data-icon="add" data-role="button" data-rel="modalview" href="#modalview-add"></a>
<a data-align="right" data-role="button" class="nav-button" href="#/">Index</a>
</div>
</header>
<ul id="pull-with-endless-listview">
</ul>
</div>
<div data-role="modalview" id="modalview-add" style="width: 95%; height: 12em;">
<div data-role="header">
<div data-role="navbar">
<span>Add Product</span> <a data-click="closeModalViewAdd" data-role="button" data-align="right">
Cancel</a>
</div>
</div>
<ul data-role="listview" data-style="inset">
<li>
<label for="username">
Product Category:</label>
<input type="text" id="name" /></li>
</ul>
<a data-click="addNew" class="addNew" type="button" data-role="button">Add New Product</a>
</div>
<script type="text/x-kendo-tmpl" id="pull-with-endless-template">
<div class="product-item">
<h3>#:CatName#</h3>
</div>
</script>
<script>
function mobileListViewPullWithEndless(e) {
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "http://mydomain.com/api/homescreenapp/36/8c177908-be9f-4474-b036-43e8cef736b5/345/800/web",
dataType: 'JSON'
}
},
serverPaging: true,
pageSize: 2
});
$("#pull-with-endless-listview").kendoMobileListView({
dataSource: dataSource,
template: $("#pull-with-endless-template").text(),
pullToRefresh: true,
endlessScroll: true
});
$("#addNew").click(function () {
loader.show();
addProductDataSource.add({
ProductName: $("#name").val(),
UnitPrice: Math.floor((Math.random() * 10) + 1)
});
});
}
function closeModalViewAdd() {
$("#modalview-add").kendoMobileModalView("close");
}
function addNew() {
addProductDataSource.add({
ProductName: $("#name").val(),
UnitPrice: Math.floor((Math.random() * 10) + 1)
});
closeModalViewAdd();
}
var addProductDataSource = new kendo.data.DataSource({
transport: {
create: {
url: " http://mydomain.com/api/homescreenapp/36/8c177908-be9f-4474-b036-43e8cef736b5/345/800/web",
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { type: "string" }
}
}
},
autoSync: true,
batch: true,
requestEnd: function () {
$("#name").val("");
}
});
</script>
<script>
window.kendoMobileApplication = new kendo.mobile.Application(document.body);
</script>
</body>
We are getting following jSon response from our webapi
{"Categories":[{"CategoryId":"305","CatName":"Clothing","Description":"","ParentId":"0","ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Category/ResizeImage/345webMan&woman.jpg","MapUrlRewrite":"Clothing"},{"CategoryId":"306","CatName":"Shoes","Description":"","ParentId":"0","ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Category/ResizeImage/345web2.jpg","MapUrlRewrite":"Shoes"},{"CategoryId":"307","CatName":"Handbags","Description":"","ParentId":"0","ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Category/ResizeImage/345web3.jpg","MapUrlRewrite":"Handbags"},{"CategoryId":"308","CatName":"Accesories","Description":"","ParentId":"0","ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Category/ResizeImage/345web4.jpg","MapUrlRewrite":"Accesories"},{"CategoryId":"309","CatName":"Luggage","Description":"","ParentId":"0","ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Category/ResizeImage/345web5.jpg","MapUrlRewrite":"Luggage"},{"CategoryId":"310","CatName":"Jewellery","Description":"","ParentId":"0","ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Category/ResizeImage/345web6.jpg","MapUrlRewrite":"Jwellery"},{"CategoryId":"344","CatName":"Eye Wear","Description":"","ParentId":"0","ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Category/ResizeImage/345web7.jpg","MapUrlRewrite":"Eye-Wear"},{"CategoryId":"345","CatName":"Watches","Description":"","ParentId":"0","ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Category/ResizeImage/345web8.jpg","MapUrlRewrite":"Top-Brands"},{"CategoryId":"346","CatName":"Hot Brands","Description":"","ParentId":"0","ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Category/ResizeImage/345webHot_Brands.jpg","MapUrlRewrite":"Hot-Deals--Offers"}],"HomeBannerImages":[{"ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Banners/ResizeImage/800webBanner_1.jpg","BannerTitle":"Banner Clothing","BannerDescription":"","CategoryId":null},{"ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Banners/ResizeImage/800webshoes-banner_2.jpg","BannerTitle":" shoes banner","BannerDescription":"","CategoryId":null},{"ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Banners/ResizeImage/800webhandbag-banner1.jpg","BannerTitle":"handbag ","BannerDescription":"","CategoryId":null},{"ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Banners/ResizeImage/800webLuggage_2.jpg","BannerTitle":"Laggege","BannerDescription":"","CategoryId":null},{"ImageName":"http://mydomailn.com/customerassets/company36/UploadImages/Banners/ResizeImage/800webjewelry_2.jpg","BannerTitle":"jewelry","BannerDescription":"","CategoryId":null}],"CustomerLogo":"http://mydomailn.com/iconnect/Images/eapparelCustomerLogo12.png"}
Code and Error :
With above code if we bind kendoMobileListView we are getting error "Uncaught SyntaxError: Unexpected token"
if we use dataType: “json” instead of dataType: “jsonp”, I am getting error like "Uncaught TypeError: Cannot call method 'slice' of undefined"
If we use dataType: “json” instead of dataType: “json array”, it is not displaying anything in listing and even in error. It mean all things will be blank.
We have gone through with all below parameter. But still not getting any success.
dataType: 'JSONP',
jsonpCallback: 'jsonCallback',
type: 'GET',
async: false,
crossDomain: true
Please guide me on this issue, I need to bind only Category name in the list.
FYI : i cann't change webapi response as it's being used by other services of client.
Thanks,
Ashish
Kendo expects the server to return a JSON array. In your case it returns an object with a Categories property where the data array is stored. You need to tell the Kendo DataSource to pull the data from .Categories using the schema.data configuration option.
... = new DataSource({
...
schema: {
data: "Categories"
}
});

Loading a server side html file into the content of a panel

I'm creating a changelog and i decided to load my changelog from .html file
I've got
Ext.define('MeridianCRM.dialogs.recentСhanges.recentСhanges', {
extend : 'Ext.window.Window',
title : 'Последние изменения на сайте',
modal : true,
height : 400,
width : 500,
resizable : false,
html: 'changes.html',
buttons: [{
text: 'Закрыть',
handler: function() {
this.up('window').close();
}
}]
});
How i can solve this ? (html: 'changes.html')
How i can load html to my window ?
There is a better solution that uses the declaration of the loader config of the panel:
loader: {
url: 'changes.html',
autoLoad: true
},
which will result in this global code.
Ext.define('MeridianCRM.dialogs.recentСhanges.recentСhanges', {
extend : 'Ext.window.Window',
title : 'Последние изменения на сайте',
modal : true,
height : 400,
width : 500,
resizable : false,
loader: {
url: 'changes.html',
autoLoad: true
},
buttons: [{
text: 'Закрыть',
handler: function() {
this.up('window').close();
}
}]
});
This is preferable, because we do not need to define a listener, nor an Ext.Ajax call.
You'd need to load the html asynchronously, then inject it into your component. So:
Ext.Ajax.request({
url: 'changes.html',
success: function(response){
// response.responseText will have your html content
// you can then feed it into your component using update()
}
});
So if you declare you component with id:
Ext.define('MeridianCRM.dialogs.recentСhanges.recentСhanges', {
extend : 'Ext.window.Window',
title : 'Последние изменения на сайте',
id: : 'my-log',
...
});
You can then do:
Ext.Ajax.request({
url: 'changes.html',
success: function(response){
Ext.getCmp('my-log').update( response.responseText );
}
});
You can `integrate' it into your panel like so:
Ext.define('MeridianCRM.dialogs.recentСhanges.recentСhanges', {
extend : 'Ext.window.Window',
title : 'Последние изменения на сайте',
id: : 'my-log',
listeners: {
'render': function()
{
Ext.Ajax.request({
url: 'changes.html',
success: function(response){
Ext.getCmp('my-log').update( response.responseText );
}
});
}
}
...
});
Notice though, that you may have issues if the returned html contains <head> tag (as the extjs page already has one).