1

Java サーブレット Web アプリケーションを php に変換しています。

次の Java コマンドを php に変換するにはどうすればよいですか?

String temp = request.getParameter("q");
String temp2 = URLDecoder.decode(temp, "UTF-8");

どんな助けでも大歓迎です...

編集:

これはクライアント コードです。

 var myJSONText = playlist.serialize();

  $.ajax({
       type : 'POST',
       url : "playlisthandler.php",
       data : {
           "q" : encodeURIComponent(myJSONText)
       },
       success : function(response) { ... },
       error : function(response) { ... },
       dataType : "json"
   });

encodeURIComponent が冗長であると言っていますか?

4

2 に答える 2

1

これを試して

$paramValue = urldecode($_GET['q']);
于 2012-05-27T15:04:50.783 に答える
1

You shouldn't have the need to do so. The request.getParameter() in servlet API and the $_REQUEST (and inherently also $_GET and $_POST) in PHP already do that based on the request character encoding. The need to do so indicates that the client side is doing it wrong by double-encoding the query string components.

As per your code you're indeed explicitly encoding the query string while jQuery already does that under the covers:

data : { "q" : encodeURIComponent(myJSONText) },

Remove the encodeURIComponent() call so that the data becomes { "q" : myJSONText }. jQuery will already take care that it will be URL-encoded. The encodeURIComponent() is only necessary when you're using plain vanilla XMLHttpRequest.

于 2012-05-27T15:24:04.067 に答える