Page 1 of 1

LoadVars Variable Return Problem?

Posted: 01 May 2011, 16:02
by coolboy714cp
In my extension, I'm loading a variable called iM to my extension from a PHP page, so I'm using LoadVars on the server.

What would be the best way to return the iM variable, and where would I put the coding at?

Code: Select all

...
function lV(urlToLoad, targetUser) {
	var _send = new LoadVars()
	var _load = new LoadVars()
	
	// Set parameters to send
	_send.mN = String(targetUser);
	
	// Handle the remote data
	_load.onLoad = function(success, errorMsg)
	{
		if (success)
		{
			trace("Data received:")
			
			trace("iM    : " + this.iM)
			iM = this.iM;
			trace("iM 1 = " + iM);
			return iM;
		}
		else
		{
			trace("Loadvar Failed. " + errorMsg)
		}
	}
	
	// Send data with POST method and receive it back in the _load object
	_send.sendAndLoad(urlToLoad, _load, "post")
}
...
The reason I'm asking this is because currently, the return code isn't working, although when I trace the variable it traces out correctly.

The return code I'm currently using in the coding above comes out to undefined, rather than the correct value that is being traced.

Does anyone know why and/or how to fix it?

Posted: 02 May 2011, 02:20
by BigFIsh

Posted: 02 May 2011, 02:31
by coolboy714cp
I just setup my crossdomain on my webhost, and it is still returning undefined. - http://mechmicecheats.org/crossdomain.xml

Posted: 02 May 2011, 04:12
by BigFIsh
Can you show us how you're sending the data back to your extension from php?

Posted: 02 May 2011, 04:28
by coolboy714cp

Code: Select all

<?php
$var = $_POST["mN"];

$con = @mysql_connect("localhost", "dbadmin1", "*password*") or die("");

if ($con) {
	@mysql_select_db("testdb1", $con);
	$query = @mysql_query("SELECT * FROM testTable WHERE username='$var' LIMIT 1;", $con);
	$res = @mysql_fetch_assoc($query);
	$resIM = $res["ismember"];
	if ($res["username"] == $var) {
		print "&iM=$resIM&mN=$var";
	} else {
		print "&iM=false&mN=$var";
	}
} else {
	print "&iM=false&mN=$var";
}
?>
I'm just using a regular PHP code to print out the variables.

Posted: 02 May 2011, 06:21
by BigFIsh
The php looks alright to me.

Looking at your sendAndLoad code, you appear to have two LoadVars. I think you should only need one.

Have you tried the example provided in http://forums.adobe.com/message/2659798#2659798?

Posted: 02 May 2011, 18:04
by coolboy714cp
Alright, I will try to do that after I setup my server. But the coding I posted above in my extension was from the loadVarsTest.as example file.