user3187715
user3187715

Reputation: 137

Passing data to Php with Jquery Ajax

I want to pass two input data to PHP with JQuery ajax I read about json, serialize and similar but I couldn't quite get a grip around it. I got:

<p><input type="text" id="domain"></p>
<p><input type="text" id="domain1"></p>
<button id="order">Search</button>

<script type="text/javascript">
    function callAjax() {
        $.ajax({
            type:  "GET",
            cache: false,
            url:   'getip.php',
            data:  ???
    });
</script>

And also what do I need on PHP file because I only got this.

$name=($_GET['']);
$surname = 
echo($name) ;
endif;

Upvotes: 0

Views: 89

Answers (3)

Ahmed Ziani
Ahmed Ziani

Reputation: 1226

$.ajax({ 
    type: "GET", 
    cache: false, 
    url: 'getip.php', 
    data = { 
        'domain': $('#domain').val(),
        'domain1': $('#domain1').val()
        };
)};

And in you php file php you can get data with :

$domain = $_GET['domain'];
$domain1 = $_GET['domain1'];

Upvotes: 2

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72269

Try this:-

<p><input type="text" id="domain" name = "domain"></p>
<p><input type="text" id="domain1" name ="domain1"></p>
<button id="order">Search</button>
function callAjax() {

$.ajax({
    type: "GET",
    cache: false,
    url: 'getip.php',
    data:{domain: $('#domain').val(),domain1: $('#domain1').val()}
});

In your php file get it like this:-

$domain = $_GET['domain'];
$domain1 = $_GET['domain1'];

Note:- Please try to read jquery a bit. It will help you.

Upvotes: 1

Tushar
Tushar

Reputation: 87233

function callAjax() {

    // Get values to send to server
    var domain = $('#domain').val();
    var domain1 = $('#domain1').val();

    $.ajax({
        type: "GET",
        cache: false,
        url: 'getip.php',
        data: {
            domain: domain,
            domain1: domain1
        }

And in php you'll get it as

$domain = $_GET['domain'];
$domain1 = $_GET['domain1'];

Docs: http://api.jquery.com/jQuery.ajax/

Upvotes: 2

Related Questions