我使用此代码,当我将 volusion api 下载到“teak_test.xml”时它可以工作,这是代码:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "teak_test.xml",
success: function(data) {
$(data).find('Products').each(function(){
var Col0 = $(this).find('ProductCode').text();
// check if Col0 = SABAH
if (Col0 === $( "span.product_code" ).text()) {
var Col1 = $(this).find('Fixed_ShippingCost').text();
$('<div><span class="product_code_title">Fixed Shiping Cost:</span><span id="inside_qty_instock"> $'+Col1+'</span></div>').appendTo('td#pricebox_top div.qty_in_stock');
}
});
}
});
});
但如果我直接从外部 url 调用 api,它就不起作用:
http://www.mywebsite.com/net/WebService.aspx?Login=admin@email.com&EncryptedPassword=123456&EDI_Name=Generic\Products&SELECT_Columns=p.ProductCode,pe.Fixed_ShippingCost
我从 volusion 找到了文章,代码是:
var api_url = "http://www.mydomain.com/net/WebService.aspx?
Login=Admin@mydomain.com&EncryptedPassword=1234567890QWERTYUIOPASDFGHJKL&EDI_
Name=Generic\Customers&SELECT_Columns=CustomerID,
AccessKey&WHERE_Column=AccessKey&WHERE_Value="C"";
var xmlhttp;
var api_response = "";
xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
api_response = xmlhttp.responseText;
} else {
//unable to connect
}
} else {
//connecting...
}
}
xmlhttp.send();
有人知道如何实施吗?我对这东西很陌生
谢谢