I am trying to pass data using ".post" method and then update MySQL table using the passed data. While doing this i am getting a error saying "Unexpected end of input". I am using laravel5 framework.
$(document).ready(function(){
$("#cl").click(function(){
var lat=$.trim($('#text1').val());
$.post("{{ URL::asset('test.php') }}",{
latitude: lat,
},function(data, status){
data = $.parseJSON(data);
console.log(data.arrResult[0]);
});
});
});
test.php:
<?php
namespace App\Http\Controllers;
use App\Test;
error_reporting(0);
function done($arrResult){
$JSON->arrResult = $arrResult;
echo json_encode($JSON);
exit();
}
//$a = $_POST['latitude'];
$failArray = array();
$failArray[0] = -2;
$failArray[1] = -2;
$ar = array(
'name' => 'PHP'
);
Test::insert($ar);
done($failArray);
?>
Test Model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Test extends Model
{
protected $table = 'test';
protected $fillable = ['name'];
}
Right now i am interested only in updating the table with some random text "PHP" (i am not using the passed data now). It is returning the $failArray when i am not using the database part.
Note: I have removed the error_reporting line and i am getting the error
Fatal error: Class 'App\Test' not found in C:\xampp\htdocs\Maze2\public\test.php on line 24
"
Thanks in advance..