Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从API资源中获取Json数组,并使用laravel中的Jquery ajax将其绑定到刀片文件中?_Php_Jquery_Laravel - Fatal编程技术网

Php 如何从API资源中获取Json数组,并使用laravel中的Jquery ajax将其绑定到刀片文件中?

Php 如何从API资源中获取Json数组,并使用laravel中的Jquery ajax将其绑定到刀片文件中?,php,jquery,laravel,Php,Jquery,Laravel,我是拉威尔和jquery的新手 我已经从API资源获取了数据,它返回了一个JSON响应 我希望通过jquery ajax将数据绑定到刀片文件 这是我从头开始的代码 1.我创建了一个名为Progress的表,其中包含5个字段 id name description goal value 2.模型:App\Progress.php class Progress extends Model { protected $table = 'progress'; protected $f

我是拉威尔和jquery的新手

我已经从API资源获取了数据,它返回了一个JSON响应

我希望通过jquery ajax将数据绑定到刀片文件

这是我从头开始的代码

1.我创建了一个名为Progress的表,其中包含5个字段

id
name
description
goal
value
2.模型:App\Progress.php

class Progress extends Model
{
     protected $table = 'progress';
     protected $fillable = [
        'id', 'name', 'goal', 'description', 'value'
    ];
    public $timestamps = false;
}
public function toArray($request)
    {
        return[
         'id' => $this->id,
         'name' => $this->name,
         'goal' => $this->goal,
         'description' => $this->description,
         'value' => $this->value,
  ];
    }
@foreach($progress as $progressdata)
        <div class="col-md-4">
             <div class = "progress">
                 <div id = "goal"> {{ $progressdata->goal }} </div>
                 <div id = "value"> {{ $progressdata->value}} </div>
              </div>
         </div>
    </div>
 @endforeach
Route::view('/', 'welcome');
  • 控制器:app/Http/Controllers/api/ProgressController.php
  • 5.Blade文件:Welcome.Blade.php

    class Progress extends Model
    {
         protected $table = 'progress';
         protected $fillable = [
            'id', 'name', 'goal', 'description', 'value'
        ];
        public $timestamps = false;
    }
    
    public function toArray($request)
        {
            return[
             'id' => $this->id,
             'name' => $this->name,
             'goal' => $this->goal,
             'description' => $this->description,
             'value' => $this->value,
      ];
        }
    
    @foreach($progress as $progressdata)
            <div class="col-md-4">
                 <div class = "progress">
                     <div id = "goal"> {{ $progressdata->goal }} </div>
                     <div id = "value"> {{ $progressdata->value}} </div>
                  </div>
             </div>
        </div>
     @endforeach
    
    Route::view('/', 'welcome');
    
    7.路由文件:web.php

    class Progress extends Model
    {
         protected $table = 'progress';
         protected $fillable = [
            'id', 'name', 'goal', 'description', 'value'
        ];
        public $timestamps = false;
    }
    
    public function toArray($request)
        {
            return[
             'id' => $this->id,
             'name' => $this->name,
             'goal' => $this->goal,
             'description' => $this->description,
             'value' => $this->value,
      ];
        }
    
    @foreach($progress as $progressdata)
            <div class="col-md-4">
                 <div class = "progress">
                     <div id = "goal"> {{ $progressdata->goal }} </div>
                     <div id = "value"> {{ $progressdata->value}} </div>
                  </div>
             </div>
        </div>
     @endforeach
    
    Route::view('/', 'welcome');
    
    我犯了这个错误

    GET http://sampleprogresswidget.test/ 500 (Internal Server Error)
    

    如何通过jquery ajax从刀片文件中的资源集合绑定dataarray。有人能帮忙吗?

    您应该像这样返回json响应

    return response()->json([
    'name' => 'Abigail',
    'state' => 'CA',
     ]);
    

    您应该像这样返回json响应

    return response()->json([
    'name' => 'Abigail',
    'state' => 'CA',
     ]);
    

    500表示您的代码或服务器配置有问题。请分享您在发出请求时看到的错误。检查控制台栏上的网络。请求URL:请求方法:获取状态代码:500内部服务器错误。这是error500,表示您的代码或服务器配置有问题。请分享您在发出请求时看到的错误。检查控制台栏上的网络。请求URL:请求方法:获取状态代码:500内部服务器错误。这是错误。我应该在哪里实现此代码。。我想从api资源中获取整个进度[],并将目标和值等数组字段传递给刀片文件..我实现了$Progress=ProgressResource::collection(Progress::paginate(4));返回响应::json($progress);在我的控制器中..获取Facade\Ignition\Exceptions\ViewException错误可能的打字错误$progress..您能提供帮助吗?.我应该在哪里实现此代码。。我想从api资源中获取整个进度[],并将目标和值等数组字段传递给刀片文件..我实现了$Progress=ProgressResource::collection(Progress::paginate(4));返回响应::json($progress);在我的控制器中..获取Facade\Ignition\Exceptions\ViewException错误可能输入错误$progress..您能帮忙吗?