Support the ongoing development of Laravel.io →
posted 10 years ago
Input
Last updated 2 years ago.
0

Please post your routes/controller

Last updated 2 years ago.
0

Your ajax looks fine, but the username, is it a variable or string ?

As mentioned by popolla, please post your routes and controller snippets.

Last updated 2 years ago.
0

Probably related to CSRF. Are you using that filter? Try to post the token as well -> csrf_token();

Last updated 2 years ago.
0

Put your code of Route POST here :D

Last updated 2 years ago.
0

Hi there, I have the same problem I want to create a simple post in ajax but it seems I am having problem with the response. I always get a 500 Internal Server Error

This is my jquery script

<script>
		$("document").ready(function(){
			$("#frm").submit(function(e){
				e.preventDefault();
				var username = $("input#username").val();
				var token =  $("input[name=_token]").val();
				var dataString = 'username='+username+'&token='+token; 
				$.ajax({
					type: "POST",
					url : "admin/login",
					data : dataString,
					success : function(data){
						console.log(data);
					}
				},"json");

		});
		});//end of document ready function
	</script>

HTML FORM

<div id="loginfrm">
		{{Form::open(array("","id"=>"frm"))}}
		<!-- <form id="frm"></form> -->
		<label id="username-label">Username</label>
		<input type="text" name="username" id="username">
		<label id="password-label">Password</label>
		{{Form::password('password',array("class"=>"frmControl","id"=>"password"))}}
		{{Form::submit('Create User')}}
		</form>
	</div>

My Route Controller

Route::post('admin/login',array('before'=>'csrf','uses'=>function(){
	$data = Input::all();
	if(Request::ajax())
	{
		$u = new User;
		$u->username = $data['username'];
		$u->password = Hash::make(Input::get( $data['password']));
		//if success
		if($u->save()){
			return 1;
		}
		//if not success
		else{
			return 0;
		}
		
	}
	
}));

My Problem is every time I submit I always get an error: POST http://localhost/hotelcraze/admin/login 500 (Internal Server Error)

I am new to Laravel 4. Please help me with this issue Thank you in advance :-)

Last updated 2 years ago.
0

I've got the same problem, did you ever find out what the issue was?

Last updated 2 years ago.
0

I think you forgot to put name="password" in your password.

Last updated 2 years ago.
0

you have to send method and token inside data```

$(document).on('click','#button',function(){
    var dataId = $(this).data("id");
    var token = $('meta[name="csrf-token"]').attr('content');
    $.ajax({

        type:'POST',
        url:"{!! URL::to('url') !!}",
        dataType: 'JSON',
        data: {
            "_method": 'POST',
            "_token": token,
            "id": dataId,
        },
        success:function(data){
            console.log('success');
            console.log(data);
        },
        error:function(){

        },
    });
});
Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Binoop binoop Joined 12 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.