jeudi 26 mars 2020

Laravel Ajax - Uncaught ReferenceError: KWS1389776 is not defined at HTMLButtonElement.onclick

I have an AJAX call to fetch a record in model and display values in a modal that must popup after GET request is done.

The javascript console is returning Uncaught ReferenceError: KWS1389776 is not defined at HTMLButtonElement.onclick

It looks some issue in how the variable is passed to javascript function in onClick event.

This is the code developed:

<button type="button" class="btn btn-label-primary btn-lg btn-upper" 
data-toggle="modal" data-target="#kt_modal_4_2" 
onClick="getPropertyDetails()">
</button>
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Property;

class PropertyController extends Controller
{
    public function details($id)
    {
        $property = Property::where('prop_id', $id)->first();
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
    }
}
function getPropertyDetails(prop_id) {
    console.log(prop_id);

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $.ajax({
        method: 'GET',
        url: '/property/details/' + prop_id,

        success: function (data) {
            console.log(data);

            if (data.status != 200) {

                console.log(data.status);
                swal.fire({
                    "title": "",
                    "text": "Ocurrió un error, contactar al administrador",
                    "type": "error",
                    showConfirmButton: !1,
                    timer: 3000,
                    onClose: () => {
                        window.location.reload();
                    }
                });

            }
            $('#kt_modal_4_2').modal("show");


        }
    });
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2QMRzZY
via IFTTT

Aucun commentaire:

Enregistrer un commentaire