jquery display Fixed_ShippingCost data from xml if .class(text) html match with ProductCode

135 views Asked by At

i use this code and it works when i download the volusion api into "teak_test.xml" here is the code:

$(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">&nbsp;$'+Col1+'</span></div>').appendTo('td#pricebox_top div.qty_in_stock');
                    }
                });
                 }
            });
        });

but it doesn't work if i call the api direct from external url:

http://www.mywebsite.com/net/[email protected]&EncryptedPassword=123456&EDI_Name=Generic\Products&SELECT_Columns=p.ProductCode,pe.Fixed_ShippingCost

i found article from volusion and the code is:

var api_url = "http://www.mydomain.com/net/WebService.aspx?
[email protected]&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();

anyone knows how to implement it? i'm new about this stuff

thanks

2

There are 2 answers

0
robertharp On

Forget it, i already able to figure it out!

it basically simple:

here's the code:

(function($){
$.ajax({url: "http://www.mydomain.com/net/[email protected]&EncryptedPassword=12345678910buchofnumberthatappear&EDI_Name=Generic\\Products&SELECT_Columns=p.ProductCode,pe.Fixed_ShippingCost&WHERE_Column=p.ProductCode&WHERE_Value=" + $("span.product_code").text(), success: function(data){
        var output = $(data);
        var fixed_shippingcost = output.find("Fixed_ShippingCost").text();
        $('<div id="FSC"><span class="product_code_title">Fixed ShipingCost:</span><span id="inside_qty_instock">&nbsp;$'+fixed_shippingcost+'</span></div>').appendTo('td#pricebox_top div.qty_in_stock');
    }
});})(jQuery);

the key is by adding \\ after "Generic" from the original api link:

http://www.mywebsite.com/net/[email protected]&EncryptedPassword=12345678910buchofnumberthatappear&EDI_Name=Generic\Products&SELECT_Columns=p.ProductCode,pe.Fixed_ShippingCost

to this link:

http://www.mydomain.com/net/[email protected]&EncryptedPassword=12345678910buchofnumberthatappear&EDI_Name=Generic\\Products&SELECT_Columns=p.ProductCode,pe.Fixed_ShippingCost&WHERE_Column=p.ProductCode&WHERE_Value=" + $("span.product_code").text()

Hope this can help yall that having the same problem get xml API from Volusion

0
user357034 On

Never ever use your Volusion API credentials with client side coding. You are creating a hugh security issue if you do.