Skip to content

Ep 19 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added jquery to package.json
debugged and fixed Access-Control-Allow-Origin in api
added api.js file with jquery ajax call to get todo tasks
added constants.js file
  • Loading branch information
chiraggshah committed Sep 14, 2015
commit c5963d2218f890bd9f216507a6a476ae9b57c5c7
11 changes: 6 additions & 5 deletions ep19-call-api-jquery/app/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import React from 'react';
import DisplayList from './DisplayList';

var rand = require('random-key');
var api = require("../utils/api");

export default class App extends React.Component {

constructor () {
super();
this.state = { title: '', todos: [
{ title: 'eggs', done: false, id: 1 },
{ title: 'banana', done: false, id: 2 },
{ title: 'bread', done: false, id: 3 }
] };
this.state = { title: '', todos: [] };
var processData = function(data) {
this.setState({todos: data.todos});
};
api.getTasks(processData.bind(this));
}

handleDone (idToBeMarkedAsDone) {
Expand Down
29 changes: 29 additions & 0 deletions ep19-call-api-jquery/app/utils/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var Constants = require("./constants");
var $ = require('jquery');

var api = {
getTasks (processData) {
var url = Constants.BASE_URL + 'todos';
this.makeAjaxCall(url, 'GET', processData)
},

makeAjaxCall (url, type, processDataCallback) {
$.ajax({
type: type,
url: url,
data: {
api_key: Constants.API_KEY
},
dataType: 'json',
success: function(data) {
console.log(data);
processDataCallback(data);
},
error: function() {
console.log("An error has occurred");
}
});
}
};

module.exports = api;
6 changes: 6 additions & 0 deletions ep19-call-api-jquery/app/utils/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var Constants = {
BASE_URL: "http://localhost:3000/api/v1/",
API_KEY: "93d2612b-20df-42e3-89fa-6af7889be7e5"
};

module.exports = Constants;
1 change: 1 addition & 0 deletions ep19-call-api-jquery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"webpack-merge": "^0.1.2"
},
"dependencies": {
"jquery": "1.11.3",
"random-key": "^0.3.2",
"react": "^0.13.3"
}
Expand Down