1

複数のディレクトリ構造へのリクエストを 1 つのページに送信するにはどうすればよいですか? たとえば、リクエストを somesite.com/users/new に送信し、somesite.com/users/delete へのリクエストを somesite.com/users/index.php に送信して、index.php ページが元の URL を確認できるようにするにはどうすればよいでしょうか。 . リダイレクトなしでこれを行う必要があります。多くのphpフレームワークとCMSがその機能を備えているため、これは非常に簡単に可能です。(ほんの数例を挙げると、Wordpress、Codeigiter、TinyMVC などです。)

私はPHPでプログラミングしています。

前もって感謝します。

4

1 に答える 1

1

index.php から /users/delete および /users/new からデータを取得するために非同期 get リクエストを実行するには、おそらく AJAX が必要になるでしょう。

JQuery プラグイン (http://jquery.com/) を使用して、AJAX 呼び出しを簡単にすることもできます。

これは、非同期の取得リクエストを作成する JQuery $.get() を使用する JavaScript の例です。

<html>
<head>

...import jquery javascript plugin...

<script>

//executes init() function on page load
$(init);

function init(){
   //binds click event handlers on buttons where id = new and delete
   // click function exectutes createUser or deleteUser depending on the 
      button that has been clicked

   $('#new').click(function(){createUser();});
   $('#delete').click(function(){deleteUser();});
}

function createUser(){

   //submits a get request to users/new and alerts the data returned
   $.get('users/new',function(data){alert('user is created : '+data)});
}

function deleteUser(){
   //submits a get request to users/delete and alerts the data returned
   $.get('users/delete',function(data){alert('user is deleted : '+data)});
}

</script>

</head>

<body>

<input id='new' type='button' />
<input id='delete' type='button' />

</body>
</html>
于 2012-07-20T01:27:33.100 に答える