PHP:通过AJAX进行Whois

I am extremely bad at AJAX (actually, I just started to learn it).

So, I write whois service on PHP and I want to make it to output the result via AJAX-request.

All I have at the moment is:

my PHP code:

$domain = $_POST['domain'];
$whois = new Whois();
header("content-type:application/json");
$res = $whois->getWhois($domain); // Calls the Whois-query function;

echo json_encode($res);

my JS code:

$('#submit').on('click', function() {
    e.preventDefault();
    var domain = $('#value').val();
});

$.ajax({
    url: 'ajax/whois.php',
    type: "post",
    data: {'domain': domain, 'action': 'whois'},
    dataType: "json",
    success: function(json) {
        $('#whoisResult').html('<h2>Whois Query result for ' + domain + '</h2>');
        $('#whoisContent').html(json.html);
    },

    error: function(xhr, status) {
        $('#whoisResult').html('<h2>Sorry, an error occured. Try again later, please!</h2>')
    }
});

As HTML I have an input: <input type="text" id="value"> and the submit button.

I searched for the script examples and tried to make something similar, but it does not work at all...

P.S. Guess you won't hit this question a negative rating :)

P.P.S: As requested, this is my response from PHP:

{"domain":"exp.cm","whois":"[Domain]
Domain: exp.cm
Status: active
Changed: 2014-02-25T12:22:00.957819+02:00

[Holder]
Type: Legal person
Name: Name, Surname
Email: email@example.com
Phone: Phone here
Address: Address goes here
Some other info

Updated: 2014-03-18T18:12:35.717462+00:00
"}

In this case you don't need the JSON datatype, just return html.

Additionally, you'll want the ajax request to be inside the click event. In your click event, you also forgot to pass the e parameter.

$domain = $_POST['domain'];
$whois = new Whois();
header("content-type:text/html");
$res = $whois->getWhois($domain); // Calls the Whois-query function;

echo $res;

js:

$('#submit').on('click', function(e) {
    e.preventDefault();
    var domain = $('#value').val();

    $.ajax({
        url: 'ajax/whois.php',
        type: "post",
        data: {'domain': domain, 'action': 'whois'},
        //dataType: "json",
        success: function(html) {
            $('#whoisResult').html('<h2>Whois Query result for ' + domain + '</h2>');
            $('#whoisContent').html(html);
        },

        error: function(xhr, status) {
            $('#whoisResult').html('<h2>Sorry, an error occured. Try again later, please!</h2>')
        }
    });
});