Rohullah Rajaee Rad Rohullah Rajaee Rad - 1 year ago 221
Ajax Question

Json Error In Laravel Ajax

I'm Use Laravel 5.2 And Ajax For Crud
Insert to Database is Correct But When Laravel Response The Browser Show Below Error In Console

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Laravel Code:

return response()->json('ok');

Jquery Code:

type: type,
url: my_url,
data: formData,
dataType: 'json',
success: function (data) {
error: function(data){// Error...
var errors = $.parseJSON(data.responseText); console.log(errors);
$.each(errors, function(index, value) { $.gritter.add({
title: 'Error',
text: value

Staus = 200

Answer Source

Can you paste your all controller code related to this error? Make sure you're not echoing anything before returning json response.

For example,

Route::get('/', function () {
    echo "hi";
    return response()->json('ok'); 

It would cause parse error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download