2017-01-06 4 views
1

私はReactとnode jの新機能です。私はreactjsで1つの "Hello World"プロジェクトを作成しました。それは正常に動作しています。ReactjsとNodejsのコード対コード

App.js

import React, { Component } from 'react'; 
import logo from './logo.svg'; 
import './App.css'; 

class App extends Component { 
    render() { 
    return (
     <div>Helllloooooooo</div> 

    ); 
    } 
} 

export default App; 

index.js

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import App from './App'; 
import './index.css'; 


// var Books = require('./apicall.js'); 

// var books = JSON.parse(document.getElementById('initial-data').getAttribute('data-json')); 
// ReactDOM.render(<Books books={books} />, document.getElementById('root')); 

ReactDOM.render(
    <App />, 
    document.getElementById('root') 
); 

index.htmlを私は新しいJS Fiを提供して作成した

<!doctype html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> 
    <!-- 
     Notice the use of %PUBLIC_URL% in the tag above. 
     It will be replaced with the URL of the `public` folder during the build. 
     Only files inside the `public` folder can be referenced from the HTML. 

     Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will 
     work correctly both with client-side routing and a non-root public URL. 
     Learn how to configure a non-root public URL by running `npm run build`. 
    --> 
    <title>React App</title> 
    </head> 
    <body> 
    <div id="root"></div> 
    <!-- 
     This HTML file is a template. 
     If you open it directly in the browser, you will see an empty page. 

     You can add webfonts, meta tags, or analytics to this file. 
     The build step will place the bundled scripts into the <body> tag. 

     To begin the development, run `npm start`. 
     To create a production bundle, use `npm run build`. 
    --> 
    </body> 
</html> 

ルAPI呼び出しのためのノードJSのsrcフォルダに、私はJSON形式で応答を見ることができるように反応するように、このノードAPIを呼び出すことができますどのように

var Client = require('node-rest-client').Client; 

var client = new Client(); 
client.registerMethod("jsonMethod", "http://webapi.com/Service.svc/xyz/value/1?format=json", "GET"); 

client.methods.jsonMethod(function (data, response) { 
    // parsed response body as js object 
    console.log(data); 
    // raw response 


}); 

。助けてください!!

+0

を実行しますNPM。これはあなたが必要とするすべての情報を見つけるでしょう。 –

+0

基本的にajaxというのは、ブラウザが新しいページをロードせずに別のリクエストをサーバーに出すということです(これはブラウザ内のJavaScriptで行うことができます)。 –

答えて

0

このデモを見ることができます。

github link

実行して:これは、AJAX呼び出しと呼ばれるもので、HTTPを介して行われるべきであるDEV

+0

が試行されましたが動作しません。 Reactのためのreduxプラグインですか? – user2768132

+0

はい、react + redux.butフロントエンド側からajaxリクエストを送ることができます。 – ryouaki

関連する問題