如何通过Ajax调用加载外部javascript
我对阿贾克斯完全陌生。在我们的网站上,我们有一个购物车页面,用户可以使用ajax添加、删除和更改商品数量,而不必为购物车加载整个页面。我的问题是,每当用户更新购物车项目时,我需要触发一些第三方外部呼叫 我有一个ajax调用,它调用jsp来计算脚本的参数。现在,这个jsp包含第三方外部脚本,我理解它需要单独启动。我正在下面添加我的代码,如果有人能帮助我,我将不胜感激如何通过Ajax调用加载外部javascript,javascript,ajax,jsp,yui,Javascript,Ajax,Jsp,Yui,我对阿贾克斯完全陌生。在我们的网站上,我们有一个购物车页面,用户可以使用ajax添加、删除和更改商品数量,而不必为购物车加载整个页面。我的问题是,每当用户更新购物车项目时,我需要触发一些第三方外部呼叫 我有一个ajax调用,它调用jsp来计算脚本的参数。现在,这个jsp包含第三方外部脚本,我理解它需要单独启动。我正在下面添加我的代码,如果有人能帮助我,我将不胜感激 var callExternalUpdate = function(secure) { var ajaxParams = "
var callExternalUpdate = function(secure) {
var ajaxParams = "secure=" + secure;
ajax('POST',
'/abc/my-ajax.jsp',
ajaxParams,
function(r) {
eval(r.responseText);
},
function(r) {
//alert(r.responseText);
}
);
}
下面是my-ajax.jsp中的代码
<script type="text/javascript" src="http://www.mywebsite.com/js/criteo_ld_0.5.4.js" async="true"></script>
<script type="text/javascript">var CRITEO_CONF = [[{
pageType: 'basket',
'Product IDs': [123],
'Prices': [10],
'Quantities': [1]
}], [6507,'ppr','us.','110',[[7721658, 7721659]],{'Product IDs':['i',1], 'Prices':['p',1], 'Quantities':['q',1]}]];
if (typeof (CRITEO) != "undefined") { CRITEO.Load(false); }
</script>
变量CRITEO_CONF=[{
页面类型:'basket',
“产品ID”:[123],
“价格”:[10],
“数量”:[1]
}],[6507,'ppr','us','110',[[7721658,7721659]],{'Product ID':[i',1],'Prices':[p',1],'Quantity':[q',1]}];
if(typeof(CRITEO)!=“undefined”){CRITEO.Load(false);}
我知道当我在javascript中使用eval时,我将省略标记。但是我如何调用外部javascript呢
请帮忙
TIA让criteo\u ldu\u 0.5.4.js加载页面,让JSP页面只返回java脚本表达式的值,而不返回任何脚本标记
var CRITEO_CONF = [[{
pageType: 'basket',
'Product IDs': [123],
'Prices': [10],
'Quantities': [1]
}], [6507,'ppr','us.','110',[[7721658, 7721659]],{'Product IDs':['i',1], 'Prices':['p',1], 'Quantities':['q',1]}]];
if (typeof (CRITEO) != "undefined") { CRITEO.Load(false); }
Magento CE或EE Criteo重新定位新OneTag
**主页-代码:**
window.criteo_q=window.criteo_q | |[];window.criteo_q.push({event:“setAccount”,account:*您的帐号**},{event:“setCustomerId”,id:“},{event:“setSiteType”,type:“d”},{event:“viewHome”});
**清单页代码:**
window.criteo_q=window.criteo_q | |[];
窗口。标准推送(
{事件:“设置帐户”,帐户:**您的帐户号**},
{事件:“setCustomerId”,id::},
{事件:“setSiteType”,类型:“d”},
{事件:“视图列表”,项:[],关键字:“});
产品页面代码:
window.criteo_q=window.criteo_q | |[];窗口。标准推送(
{事件:“设置帐户”,帐户:**您的帐户号**},
{事件:“setCustomerId”,id::},
{事件:“setSiteType”,类型:“d”},
{事件:“视图项”,项:}
);
**篮页代码:**
window.criteo_q=window.criteo_q | |[];
窗口。标准推送(
{事件:“设置帐户”,帐户:**您的帐户号**},
{事件:“setCustomerId”,id::},
{事件:“setSiteType”,类型:“d”},
{事件:“viewBasket”,项目:[
{id:,价格:,数量:}
{id:,价格:,数量:},
]});
**成功页面代码:**
window.criteo_q=window.criteo_q | |[];
window.criteo_q.push({事件:“setAccount”,account:*您的帐号**},
{事件:“setCustomerId”,id::},
{事件:“setSiteType”,类型:“d”},
{事件:“trackTransaction”,id:,项:[
{id:,价格:,数量:}
{id:,价格:,数量:},
]});
----------------------------------
就这些。。。
谢谢。除了使用jquery还有其他方法吗?您可以向dom添加标记。请参阅:在eval响应之后,我需要在ajax调用中调用这个外部脚本。我该怎么做?在eval之后添加此行。document.write(unescape(“%3Cscript src='mywebsite.com/js/criteo\u ld_0.5.4.js'async='true'type='text/javascript'%3E%3C/script%3E”);
Magento CE or EE Criteo retargeting New OneTag
**Home Page - code :**
<script type="text/javascript" src="//static.criteo.net/js/ld/ld.js" async="true"></script>
<script type="text/javascript"> window.criteo_q = window.criteo_q || []; window.criteo_q.push( { event: "setAccount", account: **Your Account Number**}, { event: "setCustomerId", id: "<?php if(Mage::getSingleton('customer/session')->isLoggedIn()) {$customerData = Mage::getSingleton('customer/session')->getCustomer();echo $customerData->getId();
}?>"}, { event: "setSiteType", type: "d"}, { event: "viewHome"} ); </script>
**Listing Page Code :**
<script type="text/javascript" src="//static.criteo.net/js/ld/ld.js" async="true"></script>
<script type="text/javascript">
window.criteo_q = window.criteo_q || [];
window.criteo_q.push(
{ event: "setAccount", account: **Your Account Number**},
{ event: "setCustomerId", id: "<?php if(Mage::getSingleton('customer/session')->isLoggedIn()) {$customerData = Mage::getSingleton('customer/session')->getCustomer();echo $customerData->getId();
}?>"},
{ event: "setSiteType", type: "d"},
{ event: "viewList", item: [<?php
$cat_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
$category = Mage::getModel('catalog/category')->load($cat_id);
$products = $category->getProductCollection()
->addCategoryFilter($category)
->addAttributeToSort('entity_id','desc')
->addAttributeToFilter('type_id','configurable')
->addAttributeToSelect('sku');
$products->setPage(1, 3);
$skus = '';
foreach ( $products as $_product ):
$skus .= '"'.$_product->getSku().'",';
endforeach;
$skus = substr($skus,0,-1);
print($skus);
?>], keywords: "<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" } ); </script>
Product Page Code :
<script type="text/javascript" src="//static.criteo.net/js/ld/ld.js" async="true"></script>
<script type="text/javascript">
window.criteo_q = window.criteo_q || []; window.criteo_q.push(
{ event: "setAccount", account: **Your Account Number**},
{ event: "setCustomerId", id: "<?php if(Mage::getSingleton('customer/session')->isLoggedIn()) {$customerData = Mage::getSingleton('customer/session')->getCustomer();echo $customerData->getId();
}?>"},
{ event: "setSiteType", type: "d"},
{ event: "viewItem", item: "<?php echo $_product->getSKU() ?>" }
);
</script>
**Basket Page Code :**
<script type="text/javascript" src="//static.criteo.net/js/ld/ld.js" async="true"></script>
<script type="text/javascript">
window.criteo_q = window.criteo_q || [];
window.criteo_q.push(
{event: "setAccount", account: **Your Account Number**},
{event: "setCustomerId", id: "<?php if(Mage::getSingleton('customer/session')->isLoggedIn()) {$customerData = Mage::getSingleton('customer/session')->getCustomer();echo $customerData->getId();
}?>"},
{event: "setSiteType", type: "d"},
{event: "viewBasket", item: [
<?php
$count = 0;
$cartLines = Mage::helper('checkout/cart')->getCart()->getItems();
foreach ($cartLines as $cartLine):
$count++;
$product = Mage::getModel('catalog/product')->load($cartLine->getProductId());
if ($product->getSpecialPrice()) {
$price = $product->getSpecialPrice();
} else {
$price = $product->getPrice();
}
/* Get Configurable Sku from Simple product SKU/ID.
* If there is no configurable/simple product set up, then just use the standard Sku display
* */
$parentId = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($cartLine->getProductId());
$configurableProductSku = Mage::getModel('catalog/product')->load($parentId)->getSku();
if ($configurableProductSku) {
$IdString .= $configurableProductSku;
}
else {
$idString .= $cartLine->getSku();
}
// $IdString .= $cartLine->getSku();
$PriceString .= $price;
$quantityString .= (int) $cartLine->getQty();
?>
<?php if( $count == count($cartLines)): ?>
{ id: "<?php echo $IdString; ?>", price: <?php echo number_format($PriceString,2,'.',' ')?>, quantity: <?php echo $quantityString ?> }
<?php else: ?>
{ id: "<?php echo $IdString; ?>", price: <?php echo number_format($PriceString,2,'.',' ')?>, quantity: <?php echo $quantityString ?> },
<?php endif; ?>
<?php
$IdString = '';
$PriceString = '';
$quantityString ='';
endforeach;
?>
]}); </script>
**Success Page Code:**
<script type="text/javascript" src="//static.criteo.net/js/ld/ld.js" async="true"></script>
<script type="text/javascript">
window.criteo_q = window.criteo_q || [];
window.criteo_q.push( {event: "setAccount", account: **Your Account Number**},
{event: "setCustomerId", id: "<?php if(Mage::getSingleton('customer/session')->isLoggedIn()) {$customerData = Mage::getSingleton('customer/session')->getCustomer();echo $customerData->getId();
}?>"},
{event: "setSiteType", type: "d"},
{event: "trackTransaction" , id: "<?php echo $this->getOrderId(); ?>", item: [
<?php
$count = 0;
foreach ($items as $item):
$count++;
/* Get Configurable Sku from Simple product SKU/ID.
* If there is no configurable/simple product set up, then just use the standard Sku display
* */
$parentId = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($item->getProductId());
$configurableProductSku = Mage::getModel('catalog/product')->load($parentId)->getSku();
if ($configurableProductSku) {
$IdString .= $configurableProductSku;
}
else {
$idString .= $item->getSku();
}
$PriceString .= $item->getPrice();
$quantityString .= (int)$item->getQtyOrdered();
?>
<?php if( $count == count($items)): ?>
{ id: "<?php echo $IdString; ?>", price: <?php echo number_format($PriceString,2,'.',' ')?>, quantity: <?php echo $quantityString ?> }
<?php else: ?>
{ id: "<?php echo $IdString; ?>", price: <?php echo number_format($PriceString,2,'.',' ')?>, quantity: <?php echo $quantityString ?> },
<?php endif; ?>
<?php
$IdString = '';
$PriceString = '';
$quantityString ='';
endforeach;
?>
]}); </script>
----------------------------------
And That's All ...