我试图从woocommerce api获取数据。我使用用户名和密码,但没有结果。我已经在邮递员中得到了一些结果,所以我的代码有误,我是这个杰森的新手。
<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">$(document).ready(function() {
$("#driver").click(function(event){
$.getJson({
dataType: "json",
data: data,
url: 'https://www.mylink.dk/wp-json/wc/v2/orders/1',
beforeSend: function (xhr) {
//May need to use "Authorization" instead
xhr.setRequestHeader("Authentication",
"Basic " + encodeBase64(ck_...... + ":" + cs......)
},
success: function (jd) {
$('#stage').html('<p> Name: ' + jd.id + '</p>');
$('#stage').append('<p>Age : ' + jd.number + '</p>');
$('#stage').append('<p> Sex: ' + jd.status + '</p>'); }
})
});
});</script>
</head>
<body>
<p>Click on the button to load result.json file −</p>
<div id="stage" style="background-color:#eee;">
STAGE
</div>
<input type="button" id="driver" value="Load Data" />
</body>
</html>