Question

Im trying to print out values from input fields with jQuery. Im using jQuery, but it wont work. Nothing is shown. Here is my code:

<script type="text/javascript">
$(document).ready(function() {
    var value;
    $('#details input[type=text]').blur(function (e) {
        value = $(e.currentTarget).val();
        $.ajax({
                type: 'GET',
                url: 'summary.php',
                data: {value: value},
                dataType: "html",
                success: function(data) { $('#table_right').append(data); },
                error: function(xhr, ajaxOptions, thrownError) { alert(thrownError); }
            });

    });
});
</script>
<style type="text/css">
#stadsnat {
    margin-top: 25px;
    display: none;
}
#stadsnat h3 {
    margin-bottom: 20px;
}
</style>
<h1>Skapa nyförsäljning</h1>
<div id="table_left" style="width: 500px;"> 
    <form name="form_edit_kund" method="post" id="details" action="addcust.php">
    <h3 style="margin-bottom: 20px;">Personuppgifter:</h3>
        <label name="firstname">F&ouml;rnamn:</label>
        <input name="fornamn" type="text" id="firstname"  />
        <label name="lastname">Efternamn:</label>
        <input name="efternamn" type="text" />
        <label name="personnr">Personnr:</label>
        <input name="personnr" type="text" maxlength="11" />
        <label name="address"> Gatuadress:</label>
        <input name="adress" type="text" />
        <label name="zip"> Postnummer:</label>
        <input name="postnr" type="text" />
        <label name="city"> Postort:</label>
        <input type="text" name="postort" />
        <label name="phone">Telefonnummer:</label>
        <input name="telefon1" type="text">
</div>
<div id="table_right" style="width: 350px">
    <h1>Summering</h1>

</div>

As you can see, Im using $.ajax to do the GEt request, but nothing is outputed.

Here is my PHP-file:

<?php

    echo $_POST['value'];

?>
Was it helpful?

Solution

You are making a GET request but are looking in $_POST.

Be consistent. Use type: 'POST', or $_GET.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top