Receive request and send to another script file

How can I send a query string to checkfolder.php?

I want to use my query string in the checkfolder.php file, but I don't know how to get the query value in the check folder.

I need to display a query string in checkfolder.php file.

Script: I also have $ _GET ['location'] that receive the request.

// function get the querystring
function getUrlVars() {    
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
            vars[key] = value;
        });
    return vars;
}

// function that run checkfolder every 5 second.
$(document).ready(function () {
    setInterval(function() { 
        // code goes here that will be run every 5 seconds.    
        var txt = ''; 
        var first = getUrlVars()["location"];    
        $.ajax({
            type: "POST",
            url: "checkfolder.php",    
            success: function(result) {
                if(parseInt(result) == "1") {
                    location.reload();
                } else {

                }

            }
        });
    }, 5000); 
});

      

I checkfoler.php I am checking for file changes. In this file, I need to write something like this:

if ($filesfound == false) {
    $location = $_GET['location'];
    $dir = "../img/uploads/".$location."/";
    if (!is_dir_empty($dir)) {
        $filesfound = true;
    }
}

      

+3


source to share


1 answer


You can pass a parameter to the request like

$.ajax({
    type: "POST",
    url: "checkfolder.php",    
    data: {
        location: getUrlVars()["location"]
    },
    success: function(result) {
        if(parseInt(result) == "1") {
            location.reload();
        } else {

        }
    }
});

      



and you can read this data in your PHP code. I'm not a PHP expert but check this out ---> http://php.net/manual/en/reserved.variables.post.php

Something like $location = $_POST['location'];

. I see they are out of date.

+2


source







All Articles