0

i have a javascript file that contains an array myfile.js. i don't have the right to change anything in this js file .

so i added a php file that i call through a web service , i call this php file with POST request with an email as a parameter .

so what i am trying to do is to get the array in myfile.js and pass it to the php file so that i can check if the email does not exists in that array then i can return as a json response true or false.

after many research i found a way to pass the js array to the php file here is my code :

 <script type='text/javascript' src='js/content/myfile.js'></script>
    <script>
        myarray  = myfile.myarray;// this works ,i can get the array 

         var hashes = window.location.href.valueOf().split('?');
        // alert(hashes[1]);
        try {
         hashes = hashes[1].split('&');
            // alert(hashes[1]);
        hashes = hashes[1].split('=');

        }
        catch ( e){
            alert(e.message);
        }
         if (hashes[1] == 0) 
        {
            hashes[1]++;
            //alert(hashes);

        top.location.href='http://direct.chancepure.com/voyance/PpSpamtram.php?array='+myarray+'&count='+hashes[1];
        }
    </script>
    <?php 
    $phpArray=$_GET["array"];
/* then i check for the email existance then return a response ......*/

what this code does is add the myarray from the js file to the url using GET : redirect to the same url but adding the array to the parameters , NOTE : i added a count parameter so that i avoid infinit loop.

this method works fine on a browser because the javascript code and the redirection works , but when i call it from Postman or other tools it does not . need your help guys.

7
  • 1
    AJAX... Its amazing technology google about it Commented Apr 11, 2017 at 10:05
  • Forget about this workaround. As already mentioned, use AJAX. It will be much better. Here in this thread are some really nice examples about serverside & clientside programming (your problem) stackoverflow.com/questions/13840429/… - if you want to learn a bit more about it :) Commented Apr 11, 2017 at 10:08
  • stackoverflow.com/a/6395746/5619088 Commented Apr 11, 2017 at 10:08
  • @MASIDDIQUI thanks dude , i know about it , but i have to start with an php file, because i'm calling a web service from a mobile application. Commented Apr 11, 2017 at 10:12
  • thank you guys , but anyone who says to use ajax probably didn't get my dilemma . i don't have the right to edit my javascript file and i'm calling this from a mobile application so it means i call a php file ,a code sample of my php file is in my question . Commented Apr 11, 2017 at 10:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.