Created
September 10, 2014 01:20
-
-
Save svolpe43/53c46e00ea48b3f5aa06 to your computer and use it in GitHub Desktop.
AJAX Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Javascript | |
$("document").ready(function(){ | |
$("#mod-form").submit(function(e){ | |
$.ajaxSetup({ | |
headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') } | |
}); | |
e.preventDefault(); | |
var name = $("input#name").val(); | |
var token = $("input[name=_token]").val(); | |
var dataString = 'name='+name+'&token='+token; | |
$.ajax({ | |
type: "POST", | |
url : "http://training/mod", | |
data : dataString, | |
success : function(data){ | |
document.getElementById('ajax').innerHTML = data; | |
} | |
},"json"); | |
}); | |
}); | |
//Form | |
{{Form::open(array("","id"=>"mod-form"))}} | |
<fieldset> | |
<div class="form-group"> | |
<input autofocus class="form-control" name="name" placeholder="Module Name" type="text"/> | |
</div><?php echo $errors->first('name'); ?> | |
<!--{{ Form::file('video') }}<br>--> | |
<div class="form-group"> | |
<button type="submit" class="btn btn-default">Submit Module</button> | |
</div> | |
</fieldset> | |
{{ Form::close() }} | |
//Route | |
Route::post('mod', array('before'=>'csrfajax', 'uses'=>'ContentController@postMod')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment