2013-05-22 6 views
0

JavaScript 기능이있는 .php 페이지가 있으며 MySQL 데이터베이스에서 문제가있는 경우 해당 함수가 실행됩니다. 나는 그 기능이 작동하는 것을 안다.플래시에서 호출 할 때 JavaScript 함수가 실행되지 않습니다.

그래서 내 PHP 파일은 다음과 같습니다

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> 

.

하지만이 같은 액션 스크립트 3에서 호출 할 때 :

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); 
    } 
} 

이는 completeHandler 기능이 제대로 thephp.php의 내용을 보여줍니다, 그렇지 않은 die("you can't") 않고는 MySQL을하지 않습니다 JavaScript에 삽입하십시오.

가능한 한 코드를 단순화하려고 했으므로 문제가 될 수 있습니까?

JavaScript는 "클라이언트"가 실행되도록 브라우저가 필요합니까?

나는 또한 ExternalInterface을 시도했지만 해당 기능에 대해 작동하지 않으며 URLRequest으로 JS 코드를 실행할 수 있는지 알고 싶습니다.

감사합니다.

Does JavaScript require the "client" to be a browser to run? 

예, 물론, 자바 스크립트가 아니라 HTTP 요청에 의해, 브라우저에 의해 실행됩니다

답변

2

당신은 일을 지적했다.

+0

ok :) 감사합니다. – void

관련 문제