-2

サーバー上のphpファイルにjavascript関数があり、AJAX経由でデータを送信したいのですが、その後、サーバー(phpファイル)はjavascript関数の入力としてデータを取得し、結果を取得した後に関数を実行しますつまり、クライアント側ではなくサーバー側で(phpとajaxを使用して)javascript関数を実行したいのです。それを行う方法はありますか?(詳細については、Web サーバーは Apache です)

4

1 に答える 1

0

file_get_contents()、file() などの php の組み込み関数を利用できます。

実際には、javascript よりも多くの機能があります。次のツイートの例をご覧ください。

  function tweet($message, $username, $password) 
  { 
    $context = stream_context_create(array( 
      'http' => array( 
        'method'  => 'POST', 
        'header'  => sprintf("Authorization: Basic %s\r\n", base64_encode($username.':'.$password)). 
                     "Content-type: application/x-www-form-urlencoded\r\n", 
        'content' => http_build_query(array('status' => $message)), 
        'timeout' => 5, 
      ), 
    )); 
    $ret = file_get_contents('http://twitter.com/statuses/update.xml', false, $context); 

    return $ret;
  }
于 2013-05-05T06:41:17.700 に答える