Ich versuche, ein ajax
Erfolg Rückruf in Hinblick auf die Ausgabe:Laravel 5: erhalten Ajax Antwort in Sicht
Controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class AjaxTestController extends Controller
{
public function ajax()
{
$nomi = array();
$nomi[0]['name'] = "alex";
$nomi[0]['surname'] = "zambonin";
$nomi[1]['name'] = "ciccio";
$nomi[1]['surname'] = "pasticcio";
return view('testAjax')->with('nomi',$nomi);
}
}
Ausblick:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>Laravel</title>
<link rel="stylesheet" href="{{ URL::asset('assets/stylesheets/frontend.css') }}">
</head>
<body>
@foreach ($nomi as $nome)
{{ $nome['name'] }}<br/>
@endforeach
</body>
<script src="{{ URL::asset('assets/javascript/frontend.js') }}"></script>
<script>
$.ajax({
url: 'testajax',
dataType: 'json',
type: 'GET',
success: function(data) {
alert(data);
}
})
</script>
</html>
Ich kann erhalten Json Daten korrekt in HTML-Seite angezeigt, aber ich kann es nicht in JavaScript-Alarm erhalten. Außerdem habe ich einen Fehler 404 auf Firefox-Konsole; Siehe hierzu image
Wie funktioniert es? Danke Alex
Hast du die Route für 'testajax' registriert? Sieht so aus, als könnte das Script keine solche Adresse finden. – KazikM