Reputation: 1896
I have a .php page, which has a JavaScript function in it, and runs that function, if something is correct in MySQL database. I know the function works.
So my php file looks like this:
thephp.php:
<?php
$should_i_run_the_function = checkDatabase();
if(!$should_i_run_the_function){die("you can't");}
?>
<!doctype html>
<html>
<head>
<script type="text/javascript" language="Javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js"></script>
<script>
function myFunction()
{
/* works in browser */
make_an_AJAX_call_and_insert_something_to_database();
}
<?php
if($should_i_run_the_function)
{
?>
myFunction();
<?php
}
?>
</script>
</head>
<body>
</body>
</html>
This works as it should, when I open the page in browser.
But when I call it from ActionScript 3, like this:
public function CallURL()
{
var request:URLRequest = new URLRequest('http://localhost/thephp.php');
var variables:URLLoader = new URLLoader();
variables.dataFormat = URLLoaderDataFormat.TEXT;
variables.addEventListener(Event.COMPLETE, Ajax_completeHandler());
try
{
variables.load(request);
}
catch (error:Error)
{
trace("Unable to load URL: " + error);
}
}
the completeHandler function shows the content of thephp.php correctly, and it does not die("you can't")
but it doesn't do the mysql insert in JavaScript.
I tried to simplify the code as much as I can, so what could be the problem?
Does JavaScript require the "client" to be a browser to run?
I also tried ExternalInterface
but it does not work for that function, and I would like to know if I can run the JS code by a URLRequest
.
Thanks !
Upvotes: 0
Views: 100
Reputation: 6946
You pointed out the thing :
Does JavaScript require the "client" to be a browser to run?
Yes, of course, the javascript is executed by the browser, not by the HTTP request.
Upvotes: 2