getting screen width into javascript variable and sending it through ajax to a php page to avoid page load

后端 未结 3 598
我在风中等你
我在风中等你 2021-01-16 16:39

This is the JS to detect the screen resolution on my page naming index.html and sending it to php, so that the values can be retrived using $

3条回答
  •  感动是毒
    2021-01-16 17:22

    You can use a javascript lib like jQuery. Instead of:

    window.location.href = "http://localhost/main.php?width=" + width + "&height=" + height;
    

    You can call:

    $.get("http://localhost/main.php?width=" + width + "&height=" + height, function(data, textStatus, jqXHR) {
        // replace the html body with the output of main.php
        $('body').html(data); // you might want to customize that
    });
    

    Documentation of $.get() jQuery function.

提交回复
热议问题