dimanche 1 novembre 2015

Jquery ajax code sometimes not working

I'm using the following code to retrieve the city based on the selected province,in a laravel 5.1 App, but sometimes it does not work and gives this error:

XMLHttpRequest cannot load http://ift.tt/1k1MryL. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.example.com' is therefore not allowed access.

My jQuery version is v1.11.3. What causes this?

//jQuery code

    $(document).ready(function(){
       var $province= $('#province');
        $province.on('change', function(){
            var $provinceValue=$province.find(':selected').val();
            var $requestURL='http://ift.tt/1SgdrFW'+$provinceValue;
            $.getJSON($requestURL, function(data){
                $('#city').empty();
                $.each(data, function(i, city){
                    $('#city').append('<option value='+city.id+' >'+city.city+'</option>');
                });
            });
        });
    });


//Route
    Route::get('profile/cities/{province_id}','UserController@cities' );

    //Method
 public function cities($province_id)
    {
        $cities=City::where('province_id', $province_id)->get();
        return $cities;
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire