Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Important:</strong></p> <p>Forget about using Ajax and encoding, decoding the path. What do you think you gain from it? Security? No. One can figure out that this is bas64 encoded or he just monitors the network traffic and reads the response from the Ajax call.</p> <p>Just do</p> <pre><code>embedSwf("flashgame","&lt;? =$path['location']?&gt;"),"&lt;?=$path['base_directory']?&gt;","800","600" ) </code></pre> <p>Really, you cannot prevent someone else seeing the data and are just making things more complicated for you.</p> <p>(<em>Or you have to decrypt the data with JavaScript.</em>)</p> <hr> <p>(<em>original answer is still correct nevertheless</em>)</p> <p>Ajax is asynchronous so something like <code>var test = decode(s);</code> will never work. The decode function will return <strong>before</strong> the Ajax call finishes.</p> <p>Instead, put your logic into the callback handler. For example, if your code was this before:</p> <pre><code>var retdata = decode('s'); // here comes code that handles retdata </code></pre> <p>put the code into a function and call it from the success handler:</p> <pre><code>function process(retdata) { // here comes code that handles retdata } function decode(s){ $.ajax({type: "POST", url: "includes/decode.inc.php", data: "s=" + s, success:function(newmsg){ process(newmsg); } }); } </code></pre> <p>This seems to be a very common problem to all beginners. You will find a lot of questions here that deal with the <a href="https://stackoverflow.com/questions/3405635/javascript-function-containing-jquery-ajax-function-returns-undefined">same problem</a>.</p> <p><strong>Update:</strong> </p> <p>It is not nice, but you could change the function to</p> <pre><code>function decode(s, cb){ $.ajax({type: "POST", url: "includes/decode.inc.php", data: "s=" + s, success:function(data){ cb(data); } }); } </code></pre> <p>and do</p> <pre><code>decode("&lt;?=base64_encode($path['location'])?&gt;", function(location) { decode("&lt;?=base64_encode($path['base_directory'])?&gt;", function(dir) { embedSwf("flashgame",location,dir,"800","600" ); }); }); </code></pre> <p><strong>Update 2:</strong></p> <p>For completeness, you can make the Ajax call synchronous, by using <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow noreferrer"><code>async: false</code></a>. Then this will work: </p> <pre><code>function decode(s){ var ret; $.ajax({type: "POST", url: "includes/decode.inc.php", data: "s=" + s, async: false, success:function(newmsg){ ret = newmsg; } }); return sync; } var val = decode(s); </code></pre> <p>However, this will block the browser until the Ajax call finished. You have to test whether this matters in your case or not.</p> <p><strong>Update 3:</strong></p> <p>You could also change your PHP script to not only accept one parameter but several and process both strings in one go.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload