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.

4

0 回答 0