gpt4 book ai didi

JavaScript 未捕获类型错误 : showcreate1 is not a function

转载 作者:行者123 更新时间:2023-12-03 03:46:25 24 4
gpt4 key购买 nike

我在写这个问题之前读过其他问题,但没有任何效果,我检查了 javascript 是否已加载,我尝试使用 jquery,其中我使用了 $ 但什么也没做..

我的问题是ajax无法正常工作,错误是标题问题。

我有一些看法,menu.blade.php代码:

@extends('cms.public.layouts.default')
@section('content')

<div class="col-md-10">
<h3 style="letter-spacing:40px;text-align:center;color:f15d5e;">PROYECTOS</h3>
</div>
<div class="col-md-2" style="padding:20px;">
<button type="button" id="buttoncreate" class="btn btn-danger">Crear Proyecto</button>

</div>
<div class="col-md-12" id="ajaxwindow">

</div>

<script>

$(document).ready(function(){
listProject();
$("#buttoncreate").click(function(e){
$("#buttoncreate").remove();
e.preventDefault();
listUploadProject();
});
});

var listProject = function()
{
$.ajax({
type:'get',
url:"{{ url('admin/project/listall') }}",
success: function(data){
$('#ajaxwindow').empty().html(data);
}
});
}
var listUploadProject = function()
{
$.ajax({
type:'get',
url:"{{ url('admin/project/create') }}",
success: function(data){
$('#ajaxwindow').empty().html(data);
}
});
}
</script>
@stop

在这个 View 中,我使用ajax并且正在工作,它显示了这个 View (listall.blade.php):

<table class="table">
<thead style="color:white">
<tr>
<th>Id</th>
<th>Slug</th>
<th>Order</th>
<th>Public</th>
<th>Path header</th>
<th>Path home</th>
<th>Fecha creación</th>
<th>Fecha ultima actualización</th>
<th><span class="glyphicon glyphicon-cog"></span></th>
</tr>
</thead>
<tbody style="color:white">
@foreach ($projects as $key => $project)
<tr>
<th>{{$project->id}}</th>
<td>{{$project->slug}}</td>
<td>{{$project->order}}</td>
<td>{{$project->public}}</td>
<td>{{$project->pathheader}}</td>
<td>{{$project->pathhome}}</td>
<td>{{ date('M j, Y', strtotime($project->created_at))}}</td>
<td>{{ date('M j, Y', strtotime($project->updated_at))}}</td>
<td><a href="{{ route('admin.projects.show', $project->id)}}" class="btn btn-info btn-sm">View</a> <a href="{{ route('admin.project.edit', $project->id)}}" class="btn btn-success btn-sm">Edit</a>
@endforeach
</tr>
</tbody>
</table>
<br><br>

如果我单击“创建”按钮,他会转到此 View (createproject.blade.php):

<div class="col-md-8 col-md-offset-2" id="createproject">

</div>
<br><br><br>

<script>
$(document).ready(function(){
showcreate1();
});

var showcreate1 = function()
{
$.ajax({
type:'get',
url:"{{ url('admin/project/createform1') }}",
success: function(data){
$('#createproject').empty().html(data);
}
});
}
</script>

Controller 调用 url '/admin/project/createform1':

 public function CreateProjectForm1()
{
return view('cms.public.views.projects.createprojectform1');
}




<div class="col-md-10">
<h3>Crear nuevo proyecto</h3>
</div>
<div class="col-md-2">
<h3>1/2</h3>
</div>
<hr>


<div class="col-md-12" id="formcreateproject">

<form method="POST" action="{{ route('admin.projects.store') }}" enctype="multipart/form-data">
<div class="form-group">
<label name="title">Slug:</label>
<input type="text" id="slug" name="slug" placeholder="ejemplo-de-slug" class="form-control form-control-sm">
<label name="order">Order:</label>
<input type="number" id="order" name="order" class="form-control form-control-sm">
<label name="public">Public:</label>
<input type="number" id="public" name="public" class="form-control form-control-sm">
<label name="body">Header</label>
<input type="file" name="pathheader" id="pathheader" class="form-control-file" aria-describedby="fileHelp"><br>
<label name="body">Home</label>
<input type="file" name="pathhome" id="pathhome" class="form-control-file" aria-describedby="fileHelp"><br>

<input type="submit" value="Crear Proyecto" id="createprojectsubmit" class="btn btn-danger btn-md">
<input type="hidden" name="_token" value="{{ Session::token() }}">
<br><br><br>

</div>
</form>

</div>

为什么最后一个 View 没有加载?

非常感谢,我们将不胜感激。

最佳答案

尝试使用这个

showcreate1 = function()
{
$.ajax({
type:'get',
url:"{{ url('admin/project/createform1') }}",
success: function(data){
$('#createproject').empty().html(data);
}
});
}

没有变种。用 var 声明它会限制它的范围。删除 var 将使其成为一个全局函数,可以在页面中的任何位置访问该函数,或者改为这样做

$(document).ready(function(){

var showcreate1 = function()
{
$.ajax({
type:'get',
url:"{{ url('admin/project/createform1') }}",
success: function(data){
$('#createproject').empty().html(data);
}
});
}
showcreate1();
});

关于JavaScript 未捕获类型错误 : showcreate1 is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45367734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com