You know it's hard to digest the fact that NodeJS is itself a Web Server, so it can contain HTML in it & we don't necessarily need a WAMP server :)
On Friday, February 15, 2013 3:33:24 PM UTC+5:30, [email protected] wrote: > > Can you please explain in detail how can I achieve that ? > I have index.html running on WAMP server & NodeJS is installed in > different folder on my machine & also listens to different port. > > Here is jQuery code > > $(document).ready(function(){ > $("button").click(function(){ > $.get("http://localhost:8081",function(data,status){ > console.log(data); > }); > }); > }); > > On Friday, February 15, 2013 2:39:04 PM UTC+5:30, greelgorke wrote: >> >> you can do $.json with jsonp calls. you server then have to return >> something like this: >> >> response.end(req.query.callback + '('+JSON.stringify(rows) + ');'); >> >> other approach is to configure a forwarding from localhost:81/api -> >> localhost:8081 >> >> Am Freitag, 15. Februar 2013 09:21:29 UTC+1 schrieb [email protected] >> : >>> >>> Hi, >>> >>> I have installed NodeJs through windows installer. >>> I have this following program for connecting to MySql db to return >>> records >>> >>> =================================================== >>> // Include http module, >>> var http = require('http'), >>> // And mysql module you've just installed. >>> mysql = require("mysql"); >>> // Create the connection. >>> // Data is default to new mysql installation and should be changed >>> according to your configuration. >>> var connection = mysql.createConnection({ >>> user: "root", >>> password: "", >>> database: "books" >>> }); >>> // Create the http server. >>> http.createServer(function (request, response) { >>> // Attach listener on end event. >>> request.on('end', function () { >>> // Query the database. >>> connection.query('SELECT * FROM authors;', function (error, rows, >>> fields) { >>> response.writeHead(200, { >>> 'Content-Type': 'x-application/json' >>> }); >>> // Send data as JSON string. >>> // Rows variable holds the result of the query. >>> response.end(JSON.stringify(rows)); >>> }); >>> }); >>> // Listen on the 8080 port. >>> }).listen(8081); >>> =================================================== >>> >>> As you can see on last line this program will listen to port 8081. >>> I have WAMP server in which I have created a project and have an >>> index.html page in it. >>> From index.html page I am hitting Node.js program above through $.get of >>> jQuery ajax. >>> >>> But WAMP is running on port 81, so Chrome is not allowing me to access >>> Cross Origin resources. >>> >>> What can I do to hit Node JS server mentioned above through the >>> index.html page hosted on WAMP server. >>> (FYI : WAMP is a PHP server) >>> >>> Please let me know. >>> >> -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
