Fetch JSON Twitter search data with WinJS - javascript

Trying to authenticate to receive search data feed from Twitter in a Windows 8 app. This is straight from a text book written when Twitter didn't require authentication so it should work although I've added user and password without any results (worse, the app terminates).
JS:
args.setPromise(WinJS.UI.processAll().then(function () {
WinJS.xhr({
url: "http://search.twitter.com/search.json?q=windows8",
//type: "GET",
user: "myusername",
password: "mypassword"
}).then(
function (result) {
var jsonData = JSON.parse(result.responseText);
//create a binding list object from the json
var bindingList = new WinJS.Binding.List(jsonData.results);
//get the list view element from the DOM
var listView = document.getElementById("sampleListView").winControl;
//bind the data sources
listView.itemDataSource = bindingList.dataSource
});
}));
HTML:
<div id="sampleListView" data-win-control="WinJS.UI.ListView"></div>

Related

Backbone Collection fetch not working

Hello i have 1 collection and model:
var Album = Backbone.Model.extend({
url: "api/album",
defaults: {
name: ""
}
});
var AlbumCollection = Backbone.Collection.extend({
url: "api/albums",
model: Album
});
If i try to fetch data from that url like this:
var newCollection = AlbumCollection();
newCollection.fetch({
success: function(data) {
console.log(11)
console.log(data)
}
})
its does not fetch data from that url - models in collection are empty. And in network tab in browser - i see there is not www.myurl.com/api/albums - call...
but if if i use jquery get it works:
$.get('api/albums', function(data) {
console.log(data);
})
return valid json.
I cant figure it out, i spent countless hours debuggin this, and searching for a problem, please help.
you missed new keyword
var newCollection = new AlbumCollection();
newCollection.fetch({
success: function(data) {
console.log(11)
console.log(data)
}
})

Backbone Login Verification

I'm asking this question in part for a whole class. We are having a hard time getting a token for login. Also, if you guys don't mind, tells us how we can improve our question asking skills.
"I am trying to use my API to assign the account we are logging in as with a token. I've tried various things, but nothing really seems to work. What needs to be sent to the URL for the token to be generated looks like this:
{
"grant_type": "password",
"username": "user#example.com",
"password": "password"
}
Then we need to be able to receive the token so that we can do some things with that account. Could anybody push me in the right direction to accomplish this? Also want to add - do we need a model and collection for our token?
Our Goal is to be able to retrieve a token, so that after we create a user we can login into our app on the login page.
// User Model and Collection. Used to input user data.
var User = Backbone.Model.extend({
url: "https://twitterapii.herokuapp.com/users"
});
//Collection for when we GET data from API
var Users = Backbone.Collection.extend({
model: User,
url: "https://twitterapii.herokuapp.com/users",
parse: function(response) {
return response.data;
}
})
//Collection for when we GET data from API
var UsersTokens = Backbone.Collection.extend({
model: User,
url: "https://twitterapii.herokuapp.com/oauth/token",
parse: function(response) {
return response.data;
}
})
var signinView = Backbone.View.extend({
tagName: 'section',
template: _.template($('#signInTemplate').html()),
events: {
"click .signinButton": 'handleLoginClick'
},
send: function(){
var signin = this.$('.signinButton').val();
console.log("clicking!!");
var email = this.$(".email").val();
var password = this.$(".password").val();
logUser: UsersTokens.fetch( {
headers: {
grant_type: password,
username: email,
password: password
} });
},
render: function(){
this.$el.html(this.template());
},
handleLoginClick: function(){
event.preventDefault();
this.send();
console.log("login clicksss!!");
}
});

Changing the page behind a modal

I'm using Foundation's reveal modal to make an ajax request to open a sign up form in a modal. On submission of the form, an ajax call is being made to create a user using devise and I receive the new page as a response in my callback. How can I set the page behind the modal as the new response page, without closing the modal as there is one more step in the form left that is optional. Here is my function so far:
function submitAjax(e){
e.preventDefault();
var user = {
email: $('#user_email').val(),
password: $('#user_password').val(),
address: $('#user_address').val(),
name: $('#user_name').val(),
type: "homeowner"
};
var lawn_profile = {
address: $('#lawn_profile_address').val(),
description: $('#lawn_profile_description').val()
};
var params = {
user: user,
lawn_profile: lawn_profile
};
debugger;
$.ajax({
url: "/users",
type: "POST",
data: params,
success: function(response){
console.log(response);
document.write(response);
debugger;
}
});
}
I have the debugger still in there from when I was trying to set the params that rails needs.

how to call web service rest based using ajax + jquery

I am calling web service on this url .
here is my code .
http://jsfiddle.net/LsKbJ/8/
$(document).ready(function () {
//event handler for submit button
$("#btnSubmit").click(function () {
//collect userName and password entered by users
var userName = $("#username").val();
var password = $("#password").val();
//call the authenticate function
authenticate(userName, password);
});
});
//authenticate function to make ajax call
function authenticate(userName, password) {
$.ajax({
//the url where you want to sent the userName and password to
url: "",
type: "POST",
// dataType: 'jsonp',
async: false,
crossDomain: true,
contentType: 'application/json',
//json object to sent to the authentication url
data: JSON.stringify({
Ticket: 'Some ticket',
Data: {
Password: "1",
Username:"aa"
}
}),
success: function (t) {
alert(t+"df")
},
error:function(data){
alert(data+"dfdfd")
}
})
}
Response
**
**
It mean that I first call this method then call login method ?
Perhaps the message means that during development, while you are writing and testing the code, use the URL:
http://isuite.c-entron.de/CentronServiceAppleDemoIndia/REST/GetNewAuthentifikationTicket
rather than:
http://isuite.c-entron.de/CentronService/REST/Login
Because you don't need the application id for the development method. You can see from the error message that you are missing the application (gu)id
The guid '61136208-742B-44E4-B00D-C32ED26775A3' is no valid application guid
Your javascript needs to be updated to use new url http://isuite.c-entron.de/CentronServiceAppleDemoIndia/GetNewAuthentifikationTicket as per the backend sode team.
Also, even if you do this, your will not be able to get reply correctly since service requires cross domain configuration entries in web.config. You have to use this reference:http://encosia.com/using-cors-to-access-asp-net-services-across-domains/ and configure server's web.config in a way so that you can call it from cross domain.

How to load remote data into grid?

I have a grid initially loaded with some data from the Store. I have search field in the form through which I can filter data. After the entering search criteria in the search field... I am calling an ajax request and getting data into the app, but unable to load this data into the store and update the grid.
var myStore = Ext.data.StoreManager.get("driveScheduleStore");
var tempStore = Ext.data.StoreManager.get("tempDSStore");
var strSearch = Ext.getCmp('VoiceDIDSearch').getValue();
Ext.Ajax.request({
url: '.../TEST/GetDriveScheduleDataFilter.php',
method: 'POST',
params: {
VDID:strSearch
},
success: function(result, request) {
var json = result.responseText;
var temp = JSON.parse(json);
myStore.load(temp.SCHEDULE);
Ext.Msg.alert('Message',myStore.getTotalCount());
},
failure: function(result, request) {
Ext.Msg.alert('Error', 'An Error occured...');
}
});
Please help.
Thanks in advance.
You can try with store.loadRawData(data, [append]).
The load function loads the store using the configured proxy, you need to use loadData to load custom json data.
http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-loadData

Categories

Resources