Home>

JS:

let url= 'get-place-price';
Let Token= Document.QuerySelector ('Meta [Name= "CSRF-TOKEN"]'). GetAttribute ('Content');
Let Content= Document.QuerySelector ('. Content');
Let Item= Document.QuerySelector ('# start_place');
FUNCTION ONCLICK () {
    Fetch (URL, {
        Headers: {
            "Content-Type": "Application /JSON",
            "Accept": "Application /JSON, Text-Plain, * /*",
            "X-Requested-With": "xmlhttprequest",
            "X-CSRF-Token": Token,
        }
        Method: 'Post',
        Credentials: "SAME-ORIGIN",
        Body: json.stringify ({
            Name: 'Tushar',
            Number: '78987'
        })
    })
        .then ((DATA)= >
 {
            content.innerhtml= data.Result;
            Console.log (Data.Result);
            Console.log (DATA);
        })
        .catch (Function (Error) {
            Console.log (Error);
        });
}
Item.ONCHANGE= FUNCTION () {
    OnClick ();
}

Route:

Route :: POST ('/Get-Place-Price', [\ App \ Http \ Controllers \ User \ CarajaxController :: class, 'place'] ->
Name ('Order.Place');

Controller:

Public Function Place (Request $ Request)
{
    $ Name= $ Request->
Get ('Name');
    $ Number= $ Request->
Get ('Number');
    RETURN RESPONSE () ->
JSON (['result'= >
'Ajax Request Submitted SuccessFully']);
}
  • Answer # 1

    Maybe to start reading the use documentation?

    Fetch (URL, {
        Headers: {
            "Content-Type": "Application /JSON",
            "Accept": "Application /JSON, Text-Plain, * /*",
            "X-Requested-With": "xmlhttprequest",
            "X-CSRF-Token": Token,
        }
        Method: 'Post',
        Credentials: "SAME-ORIGIN",
        Body: json.stringify ({
                                        Name: 'Tushar',
                                        Number: '78987'
                                    })
    })
        .then (response= >
     response.json ()) //<
    -
        .Then (Data= >
     {
            content.innerhtml= DATA;
            Console.log (DATA);
        })
        .catch (Function (Error) {
            Console.log (Error);
        });
    
  • Answer # 2

    Maybe to start reading the use documentation?

    Fetch (URL, {
        Headers: {
            "Content-Type": "Application /JSON",
            "Accept": "Application /JSON, Text-Plain, * /*",
            "X-Requested-With": "xmlhttprequest",
            "X-CSRF-Token": Token,
        }
        Method: 'Post',
        Credentials: "SAME-ORIGIN",
        Body: json.stringify ({
                                        Name: 'Tushar',
                                        Number: '78987'
                                    })
    })
        .then (response= >
     response.json ()) //<
    -
        .Then (Data= >
     {
            content.innerhtml= DATA;
            Console.log (DATA);
        })
        .catch (Function (Error) {
            Console.log (Error);
        });