简体   繁体   中英

JSON file extract is from the url

with this function, iam able to get the data from PHP page into JS. now my route has an id as parameter. iam trying to get data id. this is my js file.

$( document ).ready(function() {
    var values = $.getJSON("/json/1");
    values.done(function(data) {
        console.log(data);
    })
    .fail(function() {
        console.log( "error" );
    });
});

And the route is

Route::get('json/{notification_id}','ChartController@speedHistory')->name('speedhistory')

in the var values = $.getJSON("/json/1"); number 1 is hard coded. how i can make it dynamic?

$( document ).ready(function() {
    var id = $("#some_id").val();
    var values = $.getJSON("/json/"+id);

        values.done(function(data) {
            console.log(data);
        })
        .fail(function() {
            console.log( "error" );
        });

By this way you can get id by any method in jquery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM