问题
I am developing a Java Web Application using JSP, Servlet and AJAX. In which I try to get details of product by specific Id. When I run it on eclipse it displays the following message:
"This page is accessing information that is not under its control. This poses a security risk. Do you want to continue?"
When I press ok, it shows the product details.
If I browse in Google chrome it does not show any details. I get the response of 0 from Shopify.
Here is my ajax code which I am using to get product details:
function getProductDetails(productindex){
try{
var intProductId = getProductId(productindex);
if(intProductId != null){
var url = 'http://shop.myshopify.com/admin/products/'+intProductId+'.xml';
var httpRequest=GetXmlHttpObject();
if (httpRequest==null){
alert ("Browser does not support HTTP Request")
return
}
httpRequest.open("GET", url, true,'apikey,'password');
httpRequest.onreadystatechange = function() {processRequest(); } ;
httpRequest.send();
}
}catch(e){
alert(e);
}
}
function processRequest(){
try{
if (httpRequest.readyState == 4){
if(httpRequest.status == 200){
var xmldata=httpRequest.responseXML; //retrieve result as an XML object
showDetailsInFields(xmldata);
} else {
alert("Error in response check "+ httpRequest.status +":"+ httpRequest.statusText);
}
}
}catch(e){
alert("Error in process request"+e);
}
}
when I build and run in eclipse I get response of 200. However when I browse using chrome I get httpRequest.status = 0.
Any help would be appreciated.
Thanks
回答1:
This is JavaScript running in the browser? This likely won't work due to cross site scripting restrictions that all browsers enforce. You should make your API requests on the server and Ajax requests to your own server.
来源:https://stackoverflow.com/questions/11413020/shopify-api-call-using-ajax-and-jsp