0

"Unexpected end of input"

I'm getting this error when i trigger my $.ajax function to save user details to my database. I already checked a few topic in here but couldn't figure it out.

It has to trigger ajax to php file to save datas to my database. Simple is that. And i know that the syntax error but i already checked it in a few editors.

Couldn't find.

Any suggestions?

Form Code :

<!-- form -->
                <form id="uyelikform" name="uyelikform" action="form_kayit.php" method="post">
                <!-- <input type="hidden" name="islem" value="form-kayit"> -->

                    <div id="register-content">

                        <ul class="form-left">
                                <li>Ad Soyad</li> 
                                <li>E-Posta</li>
                                <li>Adres</li>
                                <li>Telefon</li>    
                        </ul>

                        <ul class="form-right">
                                <li><input name="adsoyad" type="text" value="<?php echo strtoupper($user_name); ?>" disabled></li>
                                <li><input name="eposta" type="text" value="<?php echo $user_email; ?>" disabled></li>
                                <li><input name="adres" type="text" value="<?php echo $adres; ?>"></li>
                                <li><input name="telefon" value="<?php echo $tel; ?>" type="text"></li>
                        </ul>

                        <div id="form-button">
                            <a class="form-gonder" href="#">KAYDET</a>
                        </div>

                    </div>
                </form>

Here is my AJAX Code :

$('.form-gonder').on('click', function(){ // FORM GONDER BUTTON EVENT
    $("#uyelikform").submit(); //SUBMIT FORM    
});


$("#uyelikform").submit(function(e) {

    $('#register-form').fadeOut(1000); // contenti kapat

    var postData = $(this).serializeArray();
    var formURL = $(this).attr("action");

    console.log(postData);

    $.ajax(
    {
        type: "POST",
        url : formURL,
        data : postData,
        dataType: "json",
        cache: false,

        success:function(data, textStatus, jqXHR) 
        {
            alert("ok");
            // $('#register-form').fadeOut(1000); // contenti kapat
        },
        error: function(jqXHR, textStatus, errorThrown) 
        {
            // alert("Başarılı Olmadı");
            console.error("The following error occured: "+ textStatus, errorThrown);

        }
    });
    e.preventDefault(); //STOP default action
});

And here is my PHP

<?php
session_start();
include("../config.php");

$fbId= $_SESSION['Adopen_User'];
// if(isset($_POST['islem']) && $_POST['islem']=="form-kayit") {

// $birth = clear($_POST["objDtarih"]);
$adres = $_POST["adres"];
$tel = $_POST["telefon"];

$kayit = @mysql_query("UPDATE tblusers SET birthday=null,address='$adres',telefon='$tel' WHERE fId=".$fbId."");

// }

?>

EDIT

When I remove JSON in my function it has worked but its not working as i expecting. Because its not updating my records in database.

How can i track AJAX call, i mean i can see that two fields are returning true values in console.log but its not updating at all.

EDIT 2

I added

if(!$kayit) {
    echo json_encode(array('returned_val' => '$fbId'));
} else {
        echo json_encode(array('returned_val' => 'basarili'));

}

And i saw that there was a sql error. Thats how i figured out.

Thank everyone.

  • 3
    You're expecting to get JSON back, as you're using dataType : JSON, but it doesn't look like you're returning anything at all ? – adeneo Dec 18 '13 at 18:52
  • 1
    ya, you return nothing from server – A. Wolff Dec 18 '13 at 18:52
  • Where in the thread are you seeing the error? In the `error: function(jqXHR, textStatus, errorThrown)` of `$.ajax`? – brandonscript Dec 18 '13 at 18:52
  • What's in config.php? – Michael Dec 18 '13 at 19:00
  • @adeneo .. thank you for all. I edited my question. please look below. And my db connect functions in there. – user3116389 Dec 18 '13 at 19:04
  • html + js + php? at the very least, please localise the source of the problem. and then post only the relevant part... – Karoly Horvath Dec 18 '13 at 19:05
  • @KarolyHorvath I wanted to be more understandable and trackable. – user3116389 Dec 18 '13 at 19:07
  • and I interpret it as lazyness... – Karoly Horvath Dec 18 '13 at 19:13
  • @KarolyHorvath horvath you are really funny.i don't understand this platform users. when i add less but focused code into the page people says that be more specific. if i write my code clear and pointing to problem, people like you are says that its lazyness.anyways. there is thousands of really lazy questions in here. anyways. i have to solve my problem. thanks anyway – user3116389 Dec 18 '13 at 19:25
  • nothing wrong with the users. you just have to learn to know what is important and what isn't. in this case, you should check your PHP script, print the input, etc... (note: you don't need AJAX to test your script, any POST will do) – Karoly Horvath Dec 18 '13 at 19:32
  • @KarolyHorvath what do you say about this? http://stackoverflow.com/questions/5004233/capture-all-of-the-forms-data-and-submit-it-to-a-php-script-jquery-ajax-post – user3116389 Dec 18 '13 at 19:43

0 Answers0