javascript - jQuery ajax function return -


I have this function that embeds the flash:

  function embedfile (target (SWF, base, width, height) {// dosomething}  

and I want to call function like this

  embedSwf ("flashgame" , Decode ("& lt;? = Base64_encode ($ path ['location'])?", Decoded ("& lt;? = Base64_encode ($ path ['base_directory']?", " 800, "600")  

The idea is that whenever anyone searches for any swf inside my website, then nothing is clear I'll change the encoding algorithm, but it's just temporary. To work that function, whenever I call the 'decode' function, it must return a value. PHP is included

< Pre> & lt ;? php echo base64_decode ($ _ POST ['s']);? & Gt;

I tried to do it, but it still works Does not

  var globvar; function process data (newmsg) {globvar = newmsg; } Function decode {$ .ajax ({type: "POST", url: "include / decode.inc.php", data: "s =" +s, success: work (newmsg) {processdata (newmsg);}} ); Return globular; }  

Important:

Forget using Ajax and encoding, Decoding path. Do you think you take advantage of it? Security? The number one can understand that this base is 64 encoded, or it just monitors network traffic and reads Ajax's response to the call.

  embedSwf ("flashgame", "800", "600")  ","  

In fact, you can not see anybody else's data and only make things more complicated for you.

( Or you have to decrypt the data with javascript.


( the original answer is still correct )

Ajax is asynchronous; something like var test = decode (s); will never work; the decoded function will return before the Ajax call. < Instead, put your logic in the callback handler. For example, if your code was first:

  var retdata = decode ('s');  

Inserts the code in a function and it succeeds Caller handler:

  Function process (rate data) Here is the code which is the data function decode (A) $ $ .ajax ({type: "POST", url : "/ Decode.inc.php is included", data: "s =" + s, success: function newmsg) {process (newmsg);}}); }  

This is a very common problem for all beginners. You will get a lot of questions here which is the deal.

Update:

This is not good, but you can specify the function

  function decode (S, CB) {$ . Ajax ({type: "post", url: "in / decode.inc.php", data: "s =" + s, success: function (data) {cb (data);}}); }  

and

  decode ("& lt;? = Base64_encode ($ path ['location'])?", Function (space) {decode ( "& Lt;? = Base64_encode ($ path ['base_directory'])?", Function (dir) {embedSwf ("flashgame", location, diamond, "800", "600");});} );  

Update 2:

For completion, you can create Ajax call using synchronous, by using. So this will work:

  function decode (s) {var ret; $ .ajax ({type: "post", url: "in / decode.inc.php", data: "s =" + s, async: false, success: work (newmsg) {ret = newmsg;}}) ; Sync back; } Var val = decode (s);  

However, this Ajax call will block the browser until it ends. You have to check whether it is in your case or not.

Update 3:

You can change your PHP scripts to not only accept your parameters, but many more, both at once Do strings process.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -