如何将此curl代码转换为适用于所有浏览器的javascript帖子请求
curl https://connect.stripe.com/oauth/token \
-d client_secret=sk_test_f7PKXx5NRBFG5r41nTrPT7qB \
-d code="{AUTHORIZATION_CODE}" \
-d grant_type=authorization_code
经过一些研究和回顾这个答案后
Convert command curl to javascript
,我看到我可以实现这样的请求
$.ajax({
url: "https://connect.stripe.com/oauth/token",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
},
type: 'POST',
dataType: 'json',
contentType: 'application/json',
processData: false,
success: function (data) {
console.log(JSON.stringify(data));
},
error: function(){
console.log(error)
}
});
如何添加client_secret,code和grant_type?
答案 0 :(得分:2)
你所要求的并不完全清楚。 但是这里有一些片段用于发出这个帖子请求 的 JQuery的强>
You can try instead
$db = mysql_connect("localhost","root","","news");
mysql_set_charset('utf8',$db);
$result = mysql_query($db, "SELECT * FROM news_list order by id LIMIT 0,4");
while ($row = mysqli_fetch_array($result))
{ ?>
<li>
<a href="#?id=<?php echo $row['id']; ?>" class="">
<div class="">
<img width="64" height="64" src="<?php echo $row['images']; ?>" class="" alt="" itemprop="image" /> </div>
<div class="">
<?php echo substr($row['description'], 0, 50); ?>
</div>
</a>
</li>
<?php } ?>
或 vanialla JavaScript :
{{1}}