1

I am coming from PHP where an AJAX call from jQuery is done like this.
html:

$('a').click(function(){
    var mydata = 'abc123';
    $.post( 'process.php', { mydata:mydata}, function(data){
            $('body').append('<h1>'+data+'</h1>');
        });
    return false;
});

php:

$post = $_POST['mydata'];
echo $post;

Question: how can i replace the PHP part with node.js to do the same thing?
also i would need to change this part of jQuery $.post( 'process.php', ...
would that look like this? $.post( 'process.js', ...?

I saw this post but i couldnt translate it from php to node

This helped out, from "Node.js for PHP developers"

In PHP, a PHP file represents an HTML page. A web server, such as Apache, accepts requests and if a PHP page is requested, the web server runs the PHP. But in Node.js, the main Node.js file represents the entire web server. It does not run inside a web server like Apache; it replaces Apache.

Community
  • 1
  • 1
t q
  • 4,593
  • 8
  • 56
  • 91
  • 1
    possible duplicate of [How do you extract POST data in node.js?](http://stackoverflow.com/questions/4295782/how-do-you-extract-post-data-in-node-js) – Michelle Tilley Apr 24 '13 at 01:29
  • (includes some good links, like http://blog.frankgrimm.net/2010/11/howto-access-http-message-body-post-data-in-node-js/ and http://jnjnjn.com/113/node-js-for-noobs-grabbing-post-content/). If you're using express, check out http://stackoverflow.com/questions/5710358/how-to-get-post-query-in-express-node-js – Michelle Tilley Apr 24 '13 at 01:30
  • @BrandonTilley thanks! will look into the links – t q Apr 24 '13 at 01:32

0 Answers0