2013-07-05 26 views
0

我想在POST isset時創建觸發器,但是來自不同的文件。Http post後的Javascript函數

file1.php:

<?php 
if (isset($_REQUEST['feed_me'])): 
    echo '<script>alert("TEST !!!");</script>'; 
endif; 
?> 

<iframe width="100%" height="300" src="file2.php"></iframe> 

file2.php:

<?php 
if (isset($_POST['feed_me'])): 

    $url = 'file1.php'; 
    $fields = array(
     'feed_me' => 1 
    ); 
    foreach($fields as $key=>$value) {$fields_string .= $key .'='.$value.'&';} 
    $fields_string = rtrim($fields_string,'&'); 
    $feed_post = curlPOST($url, $fields, $fields_string); 
    //var_dump($feed_post); 

endif; 
?> 

<form method="post" action=""> 
    <button type="submit" name="feed_me">Feed Me !!!</button> 
</form> 

如上面的代碼,當我點擊提交file2.php JavaScript警告應該出現在file1.php響應(其中有iframe到file2.php)

你能幫我解決這個問題嗎?

+1

我absolutley不知道你正在試圖做..什麼 – Zim84

+0

實際上,我想調用JavaScript在一個文件中, 而是叫後從另一個文件從文件2提交POST POST的JavaScript,file1中的JavaScript警報 –

回答

0

我認爲,Iframe行不通的parent window

替換行

<iframe width="100%" height="300" src="file2.php"></iframe> 

通過

include_once("file2.php"); 

上面會爲你工作。

+0

我明白了,但我需要它在不同的文件 –