Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what error is this Uncaught SyntaxError: Unexpected token < when using eval in jquery?

i've got a simple ajax call:

function message(){
    $.ajax({
        type: "GET",
        url: "/file/timestamp="+ timestamp,
        async: true,
        cache: false,
        success: function(data){
            var json = eval('('+data+')');
            console.log(json);
        }
    });
}

and i get an error Uncaught SyntaxError: Unexpected token < at this line: var json = eval('('+data+')');

any ideas?

thanks.

edit: some more details from the error:

$.ajax.successajax.js:9
f.Callbacks.njquery.js:2
f.Callbacks.o.fireWithjquery.js:2
wjquery.js:4
f.support.ajax.f.ajaxTransport.send.d

here is some php if is helping

public function fileAction()
{
    $this->getHelper('viewRenderer')->setNoRender();

    $filename = '/test/text.txt';

    $front  = Zend_Controller_Front::getInstance();
    $data   = $front->getRequest()->getParams();

    $lastModif      = !empty($data['timestamp']) ? $data['timestamp'] : 0;
    $currentModif   = filemtime($filename);

    while($currentModif <= $lastModif){
        usleep(10000);
        clearstatcache();
        $currentModif = filemtime($filename);
    }

    $response = array();
    $response['msg'] = file_get_contents($filename);
    $response['timestamp'] = $currentModif;

    echo json_encode($response);
}

if i run this action i get json: {"msg":"message","timestamp":1331599879} but for some reason the response is not this but some html

like image 466
Patrioticcow Avatar asked Oct 09 '22 10:10

Patrioticcow


1 Answers

It depends on what's inside data. You're running eval, so whatever's in data is being run. Please post the data here,.

like image 127
Manishearth Avatar answered Oct 13 '22 10:10

Manishearth