0

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 !

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.