我的程序中有以下 dojo 代码,我想将 code、client.key、date_joined 等值作为 json 传递。下面我有我的脚本
<table>
<tr>
<td>
<a href="/api/client/{{ client.key }}">{{ client.name }}</a>
</td>
<td>
<form method="get" action="/api/authorize">
<input type="hidden" name="redirect_uri" value="http://127.0.0.1:8000/api/client /{{client.key}}/" />
<input type="hidden" name="response_type" value="code" />
<input type="hidden" name="client_id" value="{{client.key}}" />
<input type="hidden" name="scope" value="date_joined" />
<input type="submit" value="Request" />
</form>
</td>
</tr>
</table>
我需要帮助将上述代码的参数转换为 json,并且我有以下脚本
<script type="text/javascript">
$(document).ready(function(){
$('a.authenticate').click(function(e){
e.preventDefault();
var token = this.id.replace("_", "");
$.ajax({
url: this.href,
dataType: "jsonp",
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization", "Bearer " + token)
},
success: function(data) {
var response = [];
for(key in data){
response.push(key + ":" + data[key]);
}
alert(response.join('\n'));
},
});
});
});
</script>