私の質問は私が投稿したものですが、私がしようとしているのは、適切なフォームフィールドの下のバリデーションから返されたエラーを表示することです。現在のところ、私のコンソールでこのエラーが発生しています。ajax json返信問題のLaravelアプリ
少しのコードを見てみたい場合は、改善のために提案されている変更点があるかどうかを確認してください。
"NetworkError: 405 Method Not Allowed - http://myapp.app/createorderfromform"
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
var err = JSON.parse(xhr.responseText);
$("#pageOneSubmission").click(function(event) {
event.preventDefault();
var email = $("input[name=email]").val();
var addons = [];
$('.addon-checkbox:checked').each(function() {
addons.push($(this).val())
});
$.ajax({
type: "POST",
url: '{{action('[email protected]') }}',
data:
{
email: email,
addons: addons
},
dataType: JSON,
success: function(data) {
if (!data.success) {
console.log("Errors");
} else {
console.log("No Errors");
$("#user-created-confirmation").html(data);
}
},
error: function(xhr, status, error) {
var err = JSON.parse(xhr.responseText);
$.each(err, function(key, value) {
$('input [name=key]').next().append("<p>Test</p>");
});
}
}, function(){
setTimeout(function() {
})
});
});
OrderProcessController
<?php
namespace App\Http\Controllers;
use App\Order;
use Illuminate\Http\Request;
use Sentinel;
class OrderProcessController extends JoshController
{
/*
* Create User After they complete the first part of the form.
*
*/
public function createUserAndOrder(Request $request)
{
$validation = $this->validate($request, [
'email' => 'required|confirmed|unique:users,email',
]);
$credentials = [
'email' => $request->input('email'),
'password' => $request->input('password'),
];
$user = Sentinel::registerAndActivate($credentials);
$user->role()->attach(5);
return response()->json([
'success' => true,
'errors' => null
]);
}
}
UPDATE:
私は、フォーム内の次のページに移動するからそれを維持する方法を把握しようとしているが、私のルートの問題を修正しました渡されているフォームフィールドの1つに検証エラーがある場合は、ウィザードを使用します。ユーザーがフォームの最初のページに移動してフィールドのいずれかを入力しないと、エラーが返されるためです。だから私は、入力フィールドの隣に対応するエラーを表示することができるように、エラーでajaxリクエストに戻す方法を検証してみようとしています。
しかし、私はもう一つ問題があります。最新の投稿をご覧ください。 – user3732216
あなたが何を求めているかは、あなたが最初に尋ねたものとはまったく異なります。それについて新しい質問をしてください。 –