Javascript – Uncaught SyntaxError: Unexpected token < in JSON at position 0 at Function.parse [as parseJSON] ()

javascriptjquerymysql

I have problem with adding data to mysql database here is code below (if needed i can add php code too). it says:

at Function.parse [as parseJSON] at Object.success (form.js:16) at u
(jquery.min.js:2) at Object.fireWith [as resolveWith]
(jquery.min.js:2) at k (jquery.min.js:2) at
XMLHttpRequest.(jquery.min.js:2)

$(document).ready(function() {
    $('form').submit(function(event) {
        var json;
        event.preventDefault();
        $.ajax({
            type: $(this).attr('method'),
            url: $(this).attr('action'),
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData: false,
            error: function (xhr, status, err) {
                console.error(this.props.url, status, err.toString());
            }.bind(this),
            success: function(result) {
                json = jQuery.parseJSON(result);
                if (json.url) {
                    window.location.href = '/' + json.url;
                } else {
                    alert(json.status + ' - ' + json.message);
                }
            },
        });
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            ახალი აქციის დამატება
        </h1>
       <!-- <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Forms</a></li>
            <li class="active">General Elements</li>
        </ol>-->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">

                    <!-- /.box-header -->
                    <!-- form start -->
                    <form action="/admin/addslider" method="post">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="title">აქციის სათაური</label>
                                <input type="text" class="form-control" name="title" placeholder="აქციის სათაური">
                            </div>
                            <div class="form-group">
                                <label for="image">სურათის მიმაგრება</label>
                                <input type="file" name="img">

                                <!--<p class="help-block">Example block-level help text here.</p>-->
                            </div>

                            <div class="form-group">
                                <label>აქციის აღწერა</label>
                                <textarea class="form-control" name="description" rows="3" placeholder="Enter ..."></textarea>
                            </div>

                            <div class="form-group">
                                <label for="position">აქციის პოზიცია</label>
                                <input type="number" class="form-control" name="pos" min="1" max="20" >
                            </div>
                        </div>
                        <!-- /.box-body -->

                        <div class="box-footer">
                            <button type="submit" class="btn btn-primary">ატვირთვა</button>
                        </div>
                    </form>
                </div>
                <!-- /.box -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->

Best Solution

Remove this line

json = jQuery.parseJSON(result);

It seems that response your are getting is already a JSON object.