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.

ouqas mohamed
  • 41
  • 1
  • 9
  • 1
    AJAX... Its amazing technology google about it – M A SIDDIQUI Apr 11 '17 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) http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming - if you want to learn a bit more about it :) – Twinfriends Apr 11 '17 at 10:08
  • http://stackoverflow.com/a/6395746/5619088 – Stephen Ó Connor Apr 11 '17 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. – ouqas mohamed Apr 11 '17 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 . – ouqas mohamed Apr 11 '17 at 10:16
  • @ouqasmohamed Postman doesn't execute Javascript so it is not that weird. You cannot execute myfile.js without running Javascript. (PS: Titling your question like you do, is pretty much guaranteed to be marked as duplicate, as this question is asked 10 times a day.) – Ivar Apr 11 '17 at 10:23
  • @Ivar thank you , i know that , i just explained what i tried to do , what title do you suggest ? – ouqas mohamed Apr 11 '17 at 10:27

0 Answers0