Why jQuery does not run on my xampp on Mac? - html

<!DOCTYPE html>
<html>
<head>
<title>The jQuery AJAX Example</title>
<script type = 'text/javascript'
src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>
<script type = 'text/javascript' language = 'javascript'>
$.getJSON('https://api.flickr.com/services/feeds/photos_public.gne?tags=frenchay,uwe&tagmode=any&format=json&jsoncallback=?',
function(data){
$.each(data.items, function(i,item){
$('<img/>').attr('src', item.media.m).appendTo('#images');
if ( i == 10 ) return false;
});
});
</script>
</head>
<body>
<h3>Flickr (images tagged with uwe or frenchay)</h3>
<div id = 'images'>
</div>
</body>
</html>
Hello I am trying to run this code:
<!DOCTYPE html>
<html>
<head>
<title>The jQuery AJAX Example</title>
<script type = 'text/javascript'
src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>
<script type = 'text/javascript' language = 'javascript'>
$.getJSON('https://api.flickr.com/services/feeds/photos_public.gne?tags=frenchay,uwe&tagmode=any&format=json&jsoncallback=?',
function(data){
$.each(data.items, function(i,item){
$('<img/>').attr('src', item.media.m).appendTo('#images');
if ( i == 10 ) return false;
});
});
</script>
</head>
<body>
<h3>Flickr (images tagged with uwe or frenchay)</h3>
<div id = 'images'>
</div>
</body>
</html>
If I try to run it on my own machine with xampp on my mac it will not show the photos it is like something about jquery is missing on my laptop.
The code runs in jsfiddle.

For future searches I've attached the solved result here, tightening up the spaces between = and "" fixed it for the original poster of the issue:
<!DOCTYPE html>
<html>
<head>
<title>The jQuery AJAX Example</title>
<script type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>
<script type='text/javascript' language='javascript'>
$.getJSON('https://api.flickr.com/services/feeds/photos_public.gne?tags=frenchay,uwe&tagmode=any&format=json&jsoncallback=?',
function(data){
$.each(data.items, function(i,item){
$('<img/>').attr('src', item.media.m).appendTo('#images');
if ( i == 10 ) return false;
});
});
</script>
</head>
<body>
<h3>Flickr (images tagged with uwe or frenchay)</h3>
<div id='images'>
</div>
</body>
</html>

Related

How to change from Decode Html to text normal

I have change value in textarea to Decode. I want change from value Decode Html to text normal. How I do it?
$("#editor").kendoTextArea({
change: function (e) {
var value = this.value();
var decoded = $("textarea").html(value).text();
$("#9").text(decoded);
}
});
result example: < strong >sadsadasdas< /strong >.
I want: < strong >sadsadasdas< /strong > =to=> sadsadasdas (normal text)
Here's a kendoTextArea example for you in changing HTML to text. Try this in the DOJO. The HTML is changed into text after two seconds.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2021.1.330/styles/kendo.default-v2.min.css"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2021.1.330/js/kendo.all.min.js"></script>
</head>
<body>
<textarea id="description" style="width: 100%;"></textarea>
<script>
$(document).ready(function(){
var textArea = $("#description").kendoTextArea({
value: "<b>Bold text</b>",
rows:5,
change: function(e) {
var value = e.sender.value();
e.sender.value($(value).text());
},
}).data("kendoTextArea");
setTimeout(function() {
textArea.trigger("change");
}, 2000);
});
</script>
</body>
</html>

Display ajax in html page

I'm using flask as a backend, and one of my endpoints is objectList, which returns data in this format:
[{name1:value1, name2:value2}, {name1:value3, name2:value4}]
In order to display this data on my html page, I'm using the following code:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function){
$.ajax({
url: 'localhost:5000/objectList',
method:"GET",
success: function(result){
$("#div1").html(result);
};
});
};
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
This doesn't display any data. What am I doing wrong and how can I fix this?
Edit: just a clarification, I want the data to load when the page loads, not on a button or a click
After our discussion, I find this code works properly
You have to close the parenthesis in the function ajax, and allow the access-control in the server side with this line
header("Access-Control-Allow-Origin: *");
// or replace the star with the server where you have the html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({
url: 'localhost:5000/objectList',
method:"GET",
success: function(result){
// to verifiy the result
console.log(result);
var htmlOutput = '';
// the iteration of your result because you have many entries
$.each(result, function(i, item) {
htmlOutput += ''+
'<ul>'+
'<li>name1: '+item['name1']+'</li>'+
'<li>name2: '+item['name2']+'</li>'+
'</ul>';
});
$("#div1").html(htmlOutput);
}, error: function(jqXHR, textStatus, error) {
// to verifiy either there is an error or not
console.error(textStatus);
}
});
});
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.getJSON("demo_ajax_json.js", function(result){
$.each(result, function(i, field){
$("div").append(field + " ");
});
});
});
});
</script>
</head>
<body>
<button>Get JSON data</button>
<div></div>
</body>
</html>

Html5 Div Data atribute bot showing

I am trying to set atributes for my div from Json, but i cannot get it to work. Writing the values manually works, but not when setting them. i cannot figure out what i am doing wrong.
This is my code:
<html>
<head>
<title>ThingSpeak Live Colours</title>
<link rel="stylesheet" href="css/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
var Temp;
var Humidity;
var Light;
$(document).ready(function () {
$.getJSON('http://api.thingspeak.com/channels/200101/feed/last.json', null, function (data) {
Temp = data["field1"];
Humidity = data["field2"];
Light = data["field3"];
var PreviewGaugeMeter_1 = document.getElementById("PreviewGaugeMeter_1");
var Data_percent_1 = PreviewGaugeMeter_1.getAttribute("data-percent");
PreviewGaugeMeter_1.setAttribute("data-percent", Temp);
});
});
</script>
</head>
<body>
<div class="GaugeMeter" id="PreviewGaugeMeter_1" data-percent="" data-append="%" data-size="90" data-theme="Green-Gold-Red" data-animate_gauge_colors="1" data-animate_text_colors="1" data-width="9" data-label="" data-style="Arch" data-label_color="fff"></div>
</html>
And this my JSON output:
{"created_at":"0016-12-12T00:00:00Z","entry_id":37,"field1":" 4","field2":" 7","field3":"4"}
I found a workaround, by getting "$.getJSON" to send variables to another webpage, from there i used $_GET, to retrieve them from the url, and it works.

Angular Basic ng-bind and ng-click won't work

I'm an angular beginner and it does not seem to respond to me. I'm trying to to a simple ng-click to add and subtract to a counter. I get his error:
Error: [ng:areq] http://errors.angularjs.org/1.3.15/ng/areq?p0=FirstController&p1=not%20a%20function%2C%20got%20undefined...
this is index.html:
controller.js:
var app = angular.module('app', []);
app.controller('FirstController', function($scope) {
$scope.word = "ever";
$scope.counter = 0;
$scope.add = function(amount) {
$scope.counter += amount;
};
$scope.subtract = function(amount) {
$scope.counter -= amount;
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app>
<head>
<title>Simple App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
</head>
<body>
<div ng-controller="FirstController">
<h4>The simplest adding machine ever</h4>
<button ng-click="add(1)" class="button">Add</button>
<a ng-click="subtract(1)" class="button alert">Subtract</a>
<h4>Current count: {{ counter }}</h4>
</div>
<script type="text/javascript" src="js/controller.js"></script>
</body>
</html>
Any help will be appreciated. Thanks
I think you forgot to specify what app you use , try the following code :
<html ng-app="app">
Check this it seems your missing the ng-app inclusion in the html
<html>
<head>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js#1.3.1" data-semver="1.3.1" src="//code.angularjs.org/1.3.1/angular.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="test">
<div trans-directive></div>
<h1>Hello Plunker!</h1>
<div ng-controller="trans">
<h4>The simplest adding machine ever</h4>
<button ng-click="add(1)" class="button">Add</button>
<button ng-click="subtract(1)" class="button alert">Subtract</button>
<h4>Current count: {{ counter }}</h4>
</div>
</body>
</html>
var app = angular.module("test",[]);
app.controller('trans',function($scope){
$scope.name = 'amruth';
$scope.word = "ever";
$scope.counter = 0;
$scope.add = function(amount) {
$scope.counter += amount;
};
$scope.subtract = function(amount) {
$scope.counter -= amount;
};
});
http://plnkr.co/edit/khFwKUvKkruhMa5CYtRt?p=preview
Here is your code that works: Plunkr.
Changes required :
ng-app should have a value assigned to it.
add ng-app to the body tag, as your angular script is in the head tag, html will not recognize angular
Include your controller.js after the angular but before the script code.
var app = angular.module('app', []);
app.controller('FirstController',function($scope) {
$scope.word = "ever";
$scope.counter = 0;
$scope.add = function(amount) {
$scope.counter += amount;
};
$scope.subtract = function(amount) {
$scope.counter -= amount;
};
});
<!DOCTYPE html>
<html>
<head>
<title>Simple App</title>
<script data-require="angular.js#1.3.1" data-semver="1.3.1" src="//code.angularjs.org/1.3.1/angular.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="app">
<div ng-controller="FirstController">
<h4>The simplest adding machine ever</h4>
<button ng-click="add(1)" class="button">Add</button>
<a ng-click="subtract(1)" class="button alert">Subtract</a>
<h4>Current count: {{ counter }}</h4>
</div>
{{6+2}}
</body>
</html>
1. modify html file
Here is solution for your problem.Add following line inside your html code
<html ng-app='app'>
inside <head> tag add script : <script src="app.js"></script>
2. modify controller.js
app.controller('FirstController',function($scope){});
Error occured because you added extra space between "'FirstController'," and "function($scope){})"

Separate localstorages

I have 1 site under foo.com/test1/test1.html and another at foo.com/test2/test2.html
test1.html looks like this:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
document.ready = function(){
var name = localStorage.getItem("name");
if(name){
console.log("name is defined");
}else{
console.log("name is not defined");
localStorage.setItem("name", "test1");
}
$('#name').text(name);
}
</script>
</head>
<body>
<p id="name"></p>
</body>
</html>
And test2.html is like this:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
document.ready = function(){
var name = localStorage.getItem("name");
if(name){
console.log("name is defined");
}else{
console.log("name is not defined");
localStorage.setItem("name", "test2");
}
$('#name').text(name);
}
</script>
</head>
<body>
<p id="name"></p>
</body>
</html>
My question is that is it possible to achieve that that if I go to test1, the value of name is "test1" and if I go to test2 the name will be test2. Basically I suspect that I need to name them differently but I rather not do that. Is there any good work around for this?
Thank you in advance.
local storage is defined per domain. You should keep objects in localstorage to maintain page context.
Here is solution to do it.
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
document.ready = function(){
var thispage = JSON.parse(localStorage.getItem("page1"));
if(thispage.name){
console.log("name is defined");
}else{
console.log("name is not defined");
var obj={name : "test1"}
localStorage.setItem("page1", JSON.stringify(obj));
}
}
</script>
</head>
<body>
<p id="name"></p>
</body>
</html>
similar to all pages.