jeudi 30 juin 2016

ajax success not working in php jquery


I am stuck with strange issue in form submit in modal box. Here is the ajax code which i am using.

frontend.php

$("#submit").click(function(e){
                e.preventDefault;

                   $.ajax({
                    type: 'post',
                     url:$('form#modal').attr('action'),
                    cache: false,
                    dataType: 'json',
                     data:$('form#modal').serialize(),

                     success: function (data) {
                        if(data.success == false)
                            {
                                             alert('test');
                                var arr = data.errors;
                                $.each(arr, function(index, value)
                                {
                                    if (value.length != 0)
                                    {
                                                       alert('test20');

                                    }
                                });

                            } else {


                        alert('test1');
                    }},
                    error: function(err) {
                        console.log(err);
                    }

Here is the php code of file where data is post. backend.php

header( 'Content-Type: application/json' );
$res=array();
$res['errors']=array();


    if(isset($_POST['uid'])) {

        $uid = $_POST['uid'];       
        $messages = $_POST['comment'];
        $job_id = $_POST['id'];
        $profile_pic = $_POST['pic']; ;
        $emp_id = $_POST['emp_id'];
---Some Code for database query --
         $res['success'] = true;
        echo json_encode($res);
        exit;

}

When i submit form i check the firebug console and found data is getting post but response is showing in backend file (backend.php) like this.

{"errors":[],"success":true}

I am expecting the response on frontend.php as backend.php only process the data in backend. But for some reason i am getting output in backend.php in browser.

Edit: I found line 2 > eval jquery.min.js error in firebug.


Aucun commentaire:

Enregistrer un commentaire