Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
Jquery ajax下拉列表不在laravel中显示数据城市_Jquery_Ajax_Laravel_Dropdown - Fatal编程技术网

Jquery ajax下拉列表不在laravel中显示数据城市

Jquery ajax下拉列表不在laravel中显示数据城市,jquery,ajax,laravel,dropdown,Jquery,Ajax,Laravel,Dropdown,我在下拉列表城市中使用ajax时遇到了一些限制。单击“省”部分时,它不会显示城市数据 截图: Regency.php namespace App; use Illuminate\Database\Eloquent\Model; use RajaOngkir; class Regency extends Model { protected $fillable = ['id', 'province_id', 'name']; public static functio

我在下拉列表城市中使用ajax时遇到了一些限制。单击“省”部分时,它不会显示城市数据

截图:

Regency.php

    namespace App;

use Illuminate\Database\Eloquent\Model;
use RajaOngkir;

class Regency extends Model
{
    protected $fillable = ['id', 'province_id', 'name'];

    public static function populate() {
        foreach (RajaOngkir::Kota()->all() as $kota) {
            $model = static::firstOrNew(['id' => $kota['city_id']]);
            $model->province_id = $kota['province_id'];
            $model->name = $kota['type'] . ' ' . $kota['city_name'];
            $model->save();
        }
    }

    public function province()
    {
        return $this->belongsTo('App\Province');
    }
}
Province.php

    namespace App;

use RajaOngkir;
use Illuminate\Database\Eloquent\Model;

class Province extends Model
{
    protected $fillable = ['id', 'name'];

    public static function populate() {
        foreach (RajaOngkir::Provinsi()->all() as $province) {
            $model = static::firstOrNew(['id' => $province['province_id']]);
            $model->name = $province['province'];
            $model->save();
        }
    }
}
AddressController.php

    namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Regency;

class AddressController extends Controller
{
    public function regencies(Request $request)
    {
        $this->validate($request, [
            'province_id' => 'required|exists:provinces,id'
        ]);

        return Regency::where('province_id', $request->get('province_id'))
            ->get();
    }
}
address.blade.php

{!! Form::open(['url' => '/checkout/address', 'method'=>'post', 'class' => 'form-horizontal']) !!}

    <div class="form-group {!! $errors->has('name') ? 'has-error' : '' !!}">
  {!! Form::label('name', 'Nama', ['class' => 'col-md-4 control-label']) !!}
  <div class="col-md-6">
    {!! Form::text('name', null, ['class'=>'form-control']) !!}
    {!! $errors->first('name', '<p class="help-block">:message</p>') !!}
  </div>
</div>

<div class="form-group {!! $errors->has('detail') ? 'has-error' : '' !!}">
  {!! Form::label('detail', 'Alamat', ['class' => 'col-md-4 control-label']) !!}
  <div class="col-md-6">
    {!! Form::textarea('detail', null, ['class'=>'form-control', 'rows' => 3]) !!}
    {!! $errors->first('detail', '<p class="help-block">:message</p>') !!}
  </div>
</div>

<div class="form-group {!! $errors->has('province_id') ? 'has-error' : '' !!}">
  {!! Form::label('province_id', 'Provinsi', ['class' => 'col-md-4 control-label']) !!}
  <div class="col-md-6">
    {!! Form::select('province_id', [''=>'']+DB::table('provinces')->lists('name','id'), null, ['class'=>'form-control', 'id' => 'province_selector']) !!}
    {!! $errors->first('province_id', '<p class="help-block">:message</p>') !!}
  </div>
</div>

<div class="form-group {!! $errors->has('regency_id') ? 'has-error' : '' !!}">
  {!! Form::label('regency_id', 'Kabupaten / Kota', ['class' => 'col-md-4 control-label']) !!}
  <div class="col-md-6">
    {!! Form::select('regency_id',
      old('province_id') !== null ? DB::table('regencies')->where('province_id', old('province_id'))->lists('name', 'id') : [],
      old('regency_id'), ['class'=>'form-control', 'id' => 'regency_selector']) !!}
    {!! $errors->first('regency_id', '<p class="help-block">:message</p>') !!}
  </div>
</div>

<div class="form-group {!! $errors->has('phone') ? 'has-error' : '' !!}">
  {!! Form::label('phone', 'Telepon', ['class' => 'col-md-4 control-label']) !!}
  <div class="col-md-6">
    <div class="input-group">
      <div class="input-group-addon">+62</div>
      {!! Form::text('phone', null, ['class'=>'form-control']) !!}
    </div>
    {!! $errors->first('phone', '<p class="help-block">:message</p>') !!}
  </div>
</div>

    <div class="form-group">
        <div class="col-md-6 col-md-offset-4">
            {!! Form::button('Lanjut <i class="fa fa-arrow-right"></i>', array('type' => 'submit', 'class' => 'btn btn-primary')) !!}
        </div>
    </div>

{!! Form::close() !!}
路线

试试这个

首先,在
$中添加
类型
。ajax

type: "post"
然后在路线中将
get
更改为
post

Route::post('checkout/address/regencies', 'AddressController@regencies');

您的路线是
签出/地址/摄政
,但您请求
/address/摄政
。这就是为什么会出现
404
错误

在ajax中更改url

url: '/checkout/address/regencies?province_id=' + value,

原谅我,我在路上不小心。非常感谢你帮助我。。最好的先生。
Route::post('checkout/address/regencies', 'AddressController@regencies');
url: '/checkout/address/regencies?province_id=' + value,