0

I am trying to echo data from php to jquery and the problem is that somehow jquery is not passing the data to php. The var_dump of the variable $url echo's string'' or NULL. Expected output is to echo what the user had typed on the input field on screen where the id="domain-hits" is.

HTML

<div id="domain-hits"></div>
<input onblur="checkPR()" type="text" class="input_text_metas_submit" name="url" value="http://" id="urlpr" />

Jquery / AJAX

$(function () {
    jq2('#urlpr').on('blur', function (e) {
        $.ajax({
            type: 'post',
            url: 'onlydomain.php',
            data: $('#urlpr').serialize(),
            success: function (data) {
                $("#domain-hits").html(data);
            }
        });

        e.preventDefault();
    });
});

PHP - onlydomain.php

<?php
  $url = isset($_GET['url']) ? $_GET['url'] : '';
  var_dump($url); // it echo's string ''.
?>

I am a noob in ajax please help me on this, it's much appreciated. Thanks.

1 Answer 1

4

You're sending the form data via POST by trying to retrieve it via GET. Change:

$url = isset($_GET['url']) ? $_GET['url'] : '';

to:

$url = isset($_POST['url']) ? $_POST['url'] : '';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.