I want to call the node.js file through ajax call but unable to did, help me to understand which type of URL will be entered in ajax to call the node.js file.
If you are using Jquery on the client side
you can make the request this way :
$.ajax({
url: 'your-url',
success: function(data) {
//it works, do something with the data
},
error: function() {
//something went wrong, handle the error and display a message
}
});
You can read more details here PhoneGap and JSON API
Related
am a fresher working on nodejs.
1. My friend is working on reactjs,he designed a UI where he can perform RESTFULL API methods.He would send his request to me to access API's.
2. Am working on Nodejs,i will take his request and send it to "Leadsquared.com" website which has APIs, once i receive the response from website,then i will have to forward the response to my friend back again.
Note: Am not using database, but just take request then send to website and receive response, send it back to my friend.
Need your suggestions and help!!
You need to use the http.request method.
like this:
var options = {
host: "your url",
path: '/yourPath?id=someId',
method: 'POST'
};
http.request(options, function(res) {
res.on('data', function (chunk) {
//do something
});
}).end();
I am new to Node.Js I am creating an Mean Stack application, in which I want to call 3rd party API Gandi.Net from My Node.js code.
My Node.Js plus Express Application is getting use to make rest based API which is getting consume by my Angular client.
I found a little bit help from this link https://github.com/baalexander/node-xmlrpc. ut not so much.
Do I need to make new server for XML-RPC?
If any one have did this kind of work, then any sample application will help a lot.
If any one have made any http call from node application then sample application will help.
It's quite easy to make an http call from the node server.
You can use the request module.
The documentation has tons of examples as well.
A very simple example from the module itself
var request = require('request');
request('http://www.google.com',
function (error, response, body
{
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});
I'm using Context.io's Node.js client library to get the body of emails from my account which is done in my code below.
Once I have that data, I am confused as to how I would get them over to the front-end. I'm new to the whole MEAN stack, and from my research of the basics, I have gathered that with Node, you can make the http calls, parse the json response and then write it to the server, but it seems as if I would have to make an API to then be able to call it from Angular and display it how I wish. I know that with other back-end languages like PHP, you can just write the code within the html, and not need a middle structure to get the info from PHP to the front-end. Is there an easier way than writing my own API in Node after having already made an API request to Context.io?
ctxioClient.accounts(ID).messages().get({limit:10}, function ( err, response) {
if(err) throw err;
console.log("getting responses...");
var messages = response.body;
console.log("message id is " );
console.log(messages.body);
You should implement the backend in JSON using something like res.json and make AJAX requests via Angular $http or something similar.
I need to get the data from another .js file. I am using react. In react I am passing the .js file path as URL in Ajax. Can any one send the sample code for it and tell me whether it is possible or not.
sample code for making a request with jquerys ajax:
$.ajax({
method: 'GET',
url: URL,
success: handleSuccess
});
function handleSuccess(data) {
console.log(data); // data should contain the file content
}
in my Google Chrome extension I'm trying to do an AJAX request using jQuery. This is the code I use:
//send data to the server
$.ajax({
type: "PUT",
url: "/addTransaction",
data: receivedData,
success: function(data){
console.log(data);
}
});
The problem I have is that Chrome tries to access to something like this chrome-extension://jeelhjnbimpcilllldencicbafjdgdon/addTransaction which gives of course an error. I don't want to put absolute paths because it resets the sessions in the server (node.js).
Any clue on how I can solve this? Thanks.