pragmus
pragmus

Reputation: 4053

JSON, Syntax error : unexpected token I(...)

I've a such js-function, which sends data to file, which contains a function, which sends back JSON-response:

function deleteCategory(id){
        console.log(id);
        $.ajax({
                    url: '<?php echo $cfg['options']['siteurl']; ?>/gears/ajax.deletePkgCatAsideMenu.php',
                    type: 'POST',
                    dataType: 'JSON',
                    data: {idItem:id},
                    success: function(data) {
                        console.log(data);
                        if (data.type=='error') {
                            notify(data.type, data.type, data.text);
                        } else{
                            document.location.reload();
                        }
                    },
                    error: function(v1,v2,v3) {
                        alert('Ошибка!\nПопробуйте позже.');//in english it will be: alert('Error!\nTry again later.');
                        console.log(v1,v2,v3);
                    }
                });
    }

In the end of that file these actions take place:

$q = 'DELETE FROM `pkg_cat_aside_menu` WHERE pkg_cat_ddlist_id='.$idItem;
    $db->query($q);

    exit(json_encode(array('type'=>'ok','text'=>'Удаление произведено!')));
//or in english: exit(json_encode(array('type'=>'ok','text'=>'Deleted!')));

This is a response text:

"int(13) {"type":"ok","text":"\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043e!"}"

And error syntax error: unexpected token i(...) I think, it take place, because I did actions with data base (delete), which response a deleted record number (13), and it has been included to json-respose. How to fix it?

Upvotes: 0

Views: 74

Answers (1)

Paul
Paul

Reputation: 141887

int(13) makes me think that you have a var_dump( $idItem ); somewhere earlier in your PHP code, which is causing the response to be invalid.

Upvotes: 1

Related Questions