Laravel and JQuery URL call
Laravel and JQuery URL call
我正试图从个人资料网站删除一张图片。上传正在工作,但如果我想删除,ajax调用无法正常工作。我是一个拉拉韦初学者,只是四处玩耍。
我的头像是这样的:
{{ $profileImageSection }}
<form
name="update-account"
action="{{ route('customer.account.profile.action') }}"
accept-charset="UTF-8"
enctype="multipart/form-data"
class="with-padding with-validation"
data-image-action="{{ route('customer.account.profile.image.action') }}"
data-image-delete="{{ route('customer.account.profile.image.delete') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<input type="hidden" name="account_type" value="_Private" />
<div class="holder message"></div>
我的个人资料图片部分是这样的:
<section class="profile-image">
<div class="profileimage-round">
@if (empty($image))
<figure class="placeholder"><i></i></figure>
@else
<figure class="placeholder" style="background: url({{ $image }}) no-repeat"></figure>
@endif
</div>
<form class="upload" name="upload-profile-image">
<label>Drope here</label>
<img src="{{ asset('assets/images/loader.gif') }}" />
<a href="#" class="chose">Choose</a>
<input type="file" name="profile" class="updatepic" style="/*display: block !important;*/ opacity: 0"/>
</form>
@if (!empty($image))
<form class="delete" name="delete-profile-image">
<a href="#" class="delete">Delete</a>
<input type="button" name="profile" class="deletepic" style="/*display: block !important;*/ opacity: 0"/>
</form>
@endif
我用javascript尝试的东西有点像:
$('.profile-image .delete a.delete').click(function()
{
$(this).parent().find('.deletepic').click();
});
$.('form[name=delete-profile-image]')({
url: $('form[name=update-account]').data('image-delete'),
type: 'POST',
dataType: 'json'
});
URL是正确的,我的路由如下:
Route::post('/delete', array(
'as' => 'customer.account.profile.image.delete',
'uses' => 'UserProfileController@postImage'
));
但它不起作用。我尝试了很多,但再也找不到解决方案了。我认为路由没有呼叫。有人能帮我吗?
我看到了几个问题。。
如果使用表单助手(Form::open()
/Form::close()
),则不需要手动包含隐藏的CSRF令牌元素。然而,更大的问题是您的javascript:
$('.profile-image .delete a.delete').click(function() {
$(this).parent().find('.deletepic').click();
});
$.('form[name=delete-profile-image]')({
url: $('form[name=update-account]').data('image-delete'),
type: 'POST',
dataType: 'json'
});
AJAX调用在哪里?(提示,它只是不存在。)当你可以在锚本身上启动AJAX调用时,为什么你会让锚元素触发点击表单中的隐藏按钮?尝试将HTML更改为类似的内容。。。
@if (!empty($image))
<a href="#" class="delete">Delete</a>
{{ Form::open(array('url' => route('customer.account.profile.image.delete'), 'style' => 'display: none', 'id' => 'image_delete')) }}
{{ Form::text('image', $image) }}
{{ Form::close() }}
@endif
并将您的javascript更新为以下内容:
$('.profile-image .delete a.delete').click(function() {
$('#image_delete').submit()
});
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 使用php或javascript从facebook相册URL中删除多余的部分
- Angular JS IE9 Hashbang url rewriting
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- 直接下载文件,而不是从window.open(url)
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 通过js在新选项卡中有条件地打开url
- CKFinder 3为所选文件返回错误的URL
- 如何获取不属于我项目的上一页的URL
- ReactJS映射:如何仅在url变量不为空时呈现html链接
- 在URL中传递JS对象
- 将纯文本URL转换为可单击链接
- Javascript html每点击一次就会更改url
- 以角度管理动态URL
- Mathias URL shortener
- 如何有效地将游戏数据存储在URL查询字符串中
- 使用带括号的图像URL作为jQuery的背景
- JS:检查URL中的参数,然后迭代一个参数为var的函数
- Laravel and JQuery URL call
- ASP.NET Ajax doesnt call Url