はい、問題はありません。手動のエンコーディング/デコードは必要ありません!
あなたのコードは次のようになります:
var jsonParam = '{"name":"Edgar"}'; //Sample json param
$.ajax({
...
type: "get", //This sends in url
data: {jsonParam: jsonParam}, //This will encode your json for url automatically
dataType: "json", //With this the response will be automatically json-decoded!
success: function(response){ //Assuming your server output was '{"lastName":"Villegas"}' as string
alert(response.lastName);
}
});
あなたが見ることができるように、手動のエンコーディング/デコーディングは必要なかったです。 Jqueryはそれをすべて処理します。
これが役に立ちます。あなたがjsonを手動でエンコード/デコードする必要がある場合は、javascriptのencodeURIComponent(string)
と$.parseJSON(jsonString)
メソッドを使用する必要があります。
JSONをURLの一部として送信するのではなく、AJAXリクエストをPOSTするのはなぜでしょうか。 – Endophage
@Endophageこれを行うと、サーバーからJSONにどのようにアクセスできますか? –