我有以下代码和if语句,具体取决于用户是否保存了文章。我只是尝试使用jquery从数据库中删除文章。我不确定我哪里出错了?非常感谢帮助!
查看:
<form action="{{URL::route('article-delete')}}" method="post" id="article_one_delete">
<div class="form-group">
<input type="hidden" name="first_desc" value="{{$firstrow->description}}" class="form-control">
</div>
<div class="form-group">
<input type="hidden" name="first_title" value="{{$firstrow->title1}}" class="form-control">
</div>
<button type ="button" id="Recodelete" class="btn btn-success btn-xs">UnSave</button>
{{Form::token()}}
</form>
路线:
Route::delete('/home/', array( 'as' => 'article-delete',
'uses' => 'HomeController@deletearticle'));
控制器:
public function deletearticle(){
$firsttitle = Input::get('first_title');
$articledelete = UserSaveArticle::where('user_id', Auth::id()
->where ('user_save_articles.chosen_title', $firsttitle))->delete();
return true;
JQuery的:
$(document).ready(function(){
$('#Recodelete').on('click', function(){
var article_one_delete = $('#article_one_delete').serializeArray();
var url_d = $('#article_one_delete').attr('action');
$.get(url_d, article_one_delete, function(data){
console.log(data);
});
});
});
答案 0 :(得分:1)
password = b'bXlwYXNzd29yZCE=' #this is b64, pretend its stronger
password = decode(password) # fake func for illustration
authorization = 'NLAuth nlauth_account=1111111,nlauth_email=' + username + ',nlauth_signature=' + password + ',nlauth_role=' + role
req = urllib.request.Request(url)
req.add_header('Authorization', authorization)
req.add_header('Content-Type', 'application/json')
req.add_header('Accept', 'application/json')
logging.debug(req.headers)
Route::delete('/article/{id}', ['as' => 'article-delete', 'uses' => 'HomeController@deleteArticle']);
$ id变量(文章ID)将作为方法参数提供:HomeController
function deleteArticle($id)
{
…
}