How to use JsonRestStore with my RESTful service - javascript

I try to use dojox.data.JsonRestStore with my RESTful service. I read the articles by sitepen and dojox documentation but I can't understand what they are all about.
My service gets requests like http://<host>/rest/relatedsuggestion?query=weath&results=3 and returns JSON
{
Suggestions: [
“weather channel”,
“weather forecast”,
“weather bbc”
]
}
It means that it can't understand request like http://<host>/rest/relatedsuggestion/3 which are used in every tutorial. How can I make it to understand my format? And as far as I understood the responce is also unusual for this class.
In order to try JsonRestStore I wrote the following mock up page, of cource it doesn't work and returns 4 errors "Type error: _57 is null":
<head>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js"
djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
dojo.require("dojox.data.JsonRestStore");
dojo.require("dojox.grid.DataGrid");
dojo.addOnLoad(function() {
var poStore = new dojox.data.JsonRestStore({target:"http://<host>/rest/features/relatedsuggestion"});
poStore.fetchItemByIdentity({
identity:"3433",
onItem:function(poItem){
poItem.completeOrder();
}
});
});
</script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css"
/>
</head>
<body class=" claro ">
<div id="gridElement"></div>
</body>

This IBM developerWorks article might be of help: Use Dojo's JsonRestStore with your REST services.
From your description, your service is non-standard, so you'll need to adapt both the URLs and the response mangling to fit what JsonRestStore expects. That article explains how you can do that by implementing your own service.

Related

Is jQuery still included in CouchDB?

I'm going through this CouchDB tutorial that references a few files - /_utils/script/jquery.js and /_utils/script/jquery.couch.js - that are supposed to be included.
<!DOCTYPE html>
<html>
<head><title>Tiny CouchApp</title></head>
<body>
<h1>Tiny CouchApp</h1>
<ul id="databases"></ul>
</body>
<script src="/_utils/script/jquery.js"></script>
<script src="/_utils/script/jquery.couch.js"></script>
<script>
$.couch.allDbs({
success : function(dbs) {
dbs.forEach(function(db) {
$("#databases").append('<li>'+db+'</li>');
});
}
});
</script>
</html>
When I run the Tiny CouchApp through Fauxton, I get 404 errors for those files. I'm wondering if they have moved since the tutorial was written (around 2012), but I haven't been able to find much more up-to-date documentation.
Please check out their official documentation for updated examples.
Fauxton is coded using React and does not ship with jQuery. (but you really shouldn't rely on your database to serve you some JS)

How to add google charts using Rally SDK2.1

I am hitting my head to wall with this.
APP SDK 2.0: Charts in the short term?
I followed above post to add google charts to rally report but ran into problem. I was expecting the answer by mattparrish in that post to work. but it throws following error:
sdk-debug.js:147611 Error: success callback for Deferred transformed result of Deferred transformed result of Deferred threw: TypeError: Cannot read property 'dom' of undefined
at constructor._drawChart (App.js?_dc=0.8649522877525893:36)
at constructor.launch (App.js?_dc=0.8649522877525893:30)
at constructor._applyDefaultSettingsAndLaunch (sdk-debug.js:155148)
at constructor.loadSettingsAndLaunch (sdk-debug.js:155054)
at constructor.initComponent (sdk-debug.js:155032)
at constructor (sdk-debug.js:30211)
at constructor.callParent (sdk-debug.js:4469)
at constructor [as _componentConstructor] (sdk-debug.js:34291)
at constructor.callParent (sdk-debug.js:4469)
at constructor (sdk-debug.js:144823)
This is how i am adding google jsapi to rally report:
<!DOCTYPE html>
<html>
<head>
<title>ExtPlusGoogleCharts</title>
<script type="text/javascript" src="https://rally1.rallydev.com/apps/2.1/sdk-debug.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1.0", {packages:["corechart"]});
google.setOnLoadCallback( Rally.loadScripts(
[
"App.js",
],
function() {
Rally.launchApp('CustomApp', {
name:"ExtPlusGoogleCharts"
});
}, true));
</script>
<link rel="stylesheet" type="text/css" href="app.css"/>
</head>
<body>
</body>
</html>
Can we add google charts in rally SDK2.1? If yes, how? Thanks!
Just out of curiosity, is there a special reason you'd like to use google charts? That question you referenced is pretty old and pre-dates the current charting platform in App SDK 2.1, which uses Highcharts.
There's a solid example of how to do this here: https://help.rallydev.com/apps/2.1/doc/#!/example/bare-metal-chart
I'm not all that familiar with google charts, so if you'd still like to use those someone else will probably have to post an answer on that. But hopefully you can use our built-in chart component...

Trouble getting data from Firebase database Node.js/JavaScript

Good morning everyone I'm having a little trouble with Firebase as a new user. In my previous question I asked how I could use my express server making API calls to pass that data retrieved into my firebase database and I was able to make it work! However, now I want to take that data from my database and use it to populate my DOM on the client side.
So we're clear this is how the work flow got my app goes:
Make an AJAX request from my client to my express app app.jssending a small data object {search: search} where the value for search is captured in a form on the client. (works)
Take that data object and make another AJAX request to the third party API, which returns another data object. (works)
Take that response object from the third party API and send that to my database. (works)
A script client-side pulls information from my database to populate the DOM. (not working)
Looking at the myriad of tutorials is tough and I'm following the guides I find exactly using some fine copy pasta, but I'm still stuck.
Here is the client side script firebaseData.js that I'm using to retrieve data from my database, I'm trying to get all the data at the endpoint [my database url]/user:
$(document).ready(function() {
// create object instance of my Firebase database
var myDBReference = new Firebase([my database url]);
console.log(myDBReference.child("user"))
});
And it returns this in the console client-side:
X {k: Ji, path: P, n: Ce, pc: false, then: undefined…}
And that's all I've been able to get so far. Below is my index.html where I link to firebase it's cdn and a bunch of other stuff I was just told to include in my project:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<div id="top">
<h1>Just Trying to Make a Halo App</h1>
<form id="searchForm">
<input id="searchField" type="text"></input>
<input id="searchButton" type="submit" value="search"></input>
</form>
</div>
<div id="imageContainer">
<img id="emblem">
<img id="spartan">
</div>
<div id="dataContainer">
<h2></h2>
<p></p>
</div>
<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "[my key value]",
authDomain: "[authDomain value]",
databaseURL: "[databaseURL value]",
storageBucket: "[storageBucket value",
};
firebase.initializeApp(config);
</script>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script type="text/javascript" src="request.js"></script>
<script type="text/javascript" src="firebaseData.js"></script>
</body>
</html>
In actuality the var config object has all the correct information generated from the firebase console- I wish that's all I would need to fix this! Please let me know if you require any more information I'd be happy to provide it and thanks for taking the time to check out my question.
Happy Saturday!
myDBReference.child("user") is just the reference to where the data is stored. To actually retrieve the data you will need to work with .on() or .once(). I strongly recommend you to take some time reading firebase documentation for retrieving data.
firebase.database().ref().child("user").once('value', function(snapshot) {
if(snapshot.value()){
//logs everything that is under /user
console.log(snapshot.value());
}
});
Keep in mind that if you have many users under /root/user, after retrieving the whole branch you will need to iterate over them with:
snapshot.forEach(function(childSnap){
console.log(childSnap.val());
});
Update:
Since I see you are not working with any SPA framework such as Angular (with angularfire), if you want to display the data that you are retrieving from firebase you will need to work setting an element id and than call document.getElementById() inside your callback to manipulate it.
<p id="username"></p>
document.getElementById("username").value = snapshot.val();

Bing Image Archive Ajax Error

I have made an Ajax call to Bing to get its daily image, however i get an error in the console:
this is the full code its on a localhost using wamp
index.php
<head>
<script src="jquery.min.js"></script>
</head>
<body>
<div id="output"></div>
</body>
<script type="text/javascript">
$.ajax({
url : "http://bing.com/HPImageArchive.aspx?format=js&idx=0&n=1",
dataType:"jsonp",
});
function mycallback(data)
{
$('#output').html(data.images[0].url);
}
</script>
I think you should study the documention for jquery ajax call.
<head>
<script src="jquery.min.js"></script>
</head>
<body>
<div id="output"></div>
</body>
<script type="text/javascript">
(function() {
var bingImagesUrl = "http://bing.com/HPImageArchive.aspx";
$.getJSON( bingImagesUrl, {
idx:0,
n:1,
format: "js"
}).done(function( data ) {
$('#output').html(data.images[0].url);
});
})();
</script>
#Below_the_Radar: your answer does not really help as OP is likely getting the same error even if he makes the Ajax call correctly.
According to Is there a way to get Bing's photo of the day?, it seems that Bing.com only supports XML, JSON, and RSS. I guess OP want to make the call with dataType: "jsonp" probably because he would like to bypass the browsers same-origin policy.
This can be solved client-side in browser by using a Chrome extension, but I guess that is not OP's use case. I bet OP is trying to get a picture from Bing's archive and thus use it in his own website. If that is the case, it has no solution as we need to have "Access-Control-Allow-Origin": "*" in the response's headers returned by Bing, which we do not have control.
I suggest considering an alternative. Try this: https://source.unsplash.com/

Why so many web pages contain such a strange code snippet in header?

I've noticed for quite a long time that strange domains such like jsev.com, cssxx.com appered in my firefox status bar from time to time, I always wonder why so many web pages contains resources from these strange domains. I googled it, but found nothing. I guess it's some kind of virus which infect the servers and insert the code. Here is a sample taken from page header of http://www.eflorenzano.com/threadexample/blog/:
<script language="javascript" src="http://i.jsev.com./base.2032621946.js"> </script>
<body onmousemove="return fz3824();">
<LINK REL="stylesheet" TYPE="text/css" HREF="http://i.cssxx.com./base2032621947.css">
<SCRIPT LANGUAGE="JAVASCRIPT" SRC="http://i.js.com./base2032621947.js"></SCRIPT>
<SCRIPT LANGUAGE="JAVASCRIPT">
function getuseragnt()
{ var agt = navigator.userAgent.toLowerCase();
agt = agt.replace(/ /g, "");
return agt;
}
document.write("<LINK REL='stylesheet' TYPE='text/css' HREF='http://i.css2js.com./base.css" + getuseragnt() + "_2032621947'>")
</SCRIPT>
edit: I am on a debian box, only on firefox I see this code, I just tried opera, this code doesn't appear in opera, really strange, never heard of firefox having such problems.
This happens if you are using one of Princeton university's CoDeeN project proxy servers. CoDeeN is an academic testbed content distribution network. When you browse a web page using CoDeeN proxy it injects some HTML code to the site's original HTML and redirects requests sent to pseudo adresses to the project's servers.
Some of the pseudo addresses are:
http://i.cssxx.com./base0877861956.css | i.cssxx.com.
http://i.jsev.com./base.0877861955.js | i.jsev.com./
http://i.html.com./base0877861956.html | i.html.com.
http://i.js.com./base0877861956.js | i.js.com./
http://i.css2js.com./base.css | i.css2js.com.
Some or all CoDeeN's proxy servers appear as anonymous proxy servers list.
CoDeeN project page: http://codeen.cs.princeton.edu/
It may be a browser worm installed on your machine. Should scan entire system.
I see nothing unusual about that page. Check your system. Here's the code I received:
<head><title>Tutorial 2</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/reset/reset-min.css">
<link rel="stylesheet" type="text/css" href="http://media.eflorenzano.com/css/example2.css">
<script type="text/javascript" src="http://media.eflorenzano.com/js/jquery-1.2.2.min.js"></script>
<script type="text/javascript" src="http://media.eflorenzano.com/js/jquery.form.js"></script>
<script type="text/javascript">
var _POSTER = '';
var _FORM = '<textarea id="id_comment" rows="10" cols="40" name="comment"></textarea>';
var _FORM_URL = '/threadexample/threadedcomments/comment/9/1/json/';
var _REGISTER_URL = '/threadexample/register';
var _CHECK_EXISTS_URL = '/threadexample/check_exists';
var _LOGIN_URL = '/threadexample/login';
var _IS_FOCUSED = null;
var _ARROW_IMG_BASE = 'http://media.eflorenzano.com/img/arrow_';
var _VOTE_BASE = '/threadexample/vote/';
</script>
<script type="text/javascript" src="http://media.eflorenzano.com/js/example2.js"></script>
</head>
DNS poisoning?
I agree with Mediashakers
That cause you're using CoDeeN project proxy servers
Try use no proxy, it will see the difference
That could very well be the case, as this does kinda look like some shady code. What if you use a different computer, does the source look the same?
Hm ... No solution here, but as a datapoint: It doesn't look at all like that for me (Firefox 3.0.3, in Gentoo Linux). I get the following interesting elements in the header:
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/reset/reset-min.css">
<link rel="stylesheet" type="text/css" href="http://media.eflorenzano.com/css/example2.css">
<script type="text/javascript" src="http://media.eflorenzano.com/js/jquery-1.2.2.min.js">
<script type="text/javascript" src="http://media.eflorenzano.com/js/jquery.form.js">
[...]
<script type="text/javascript" src="http://media.eflorenzano.com/js/example2.js">
This looks fairly clean to me; four references to resources on the same server, plus one CSS from what looks like Yahoo!. Strange, I wonder why it looked so different for you. Hopefully some true web wizard can shed some light on that.
Also, I notice that all the weird-looking URI:s have domain names that end in a period, which I don't think is even legal. I Googled it, and found some old Digg thread, but was unable to locate the exact comment that mentioned the weird-looking URI:s. Strange.

Categories

Resources