我想通过ajax请求从主题folder/loyalty.tpl
到/public_html/test/modules/loyalty/LoyaltyModule.php
在prestshop 1.6.1.5
<input id="Gcash_id" name="Gcash_id" type="text" class="form-control grey" placeholder="Enter your G cash code you will get Gcash amount" /><br>
<div id="errorBoxgcash" style="color:#FF0000; font-size:16px;"> </div><br>
<button type="submit" name="Submit" value="OK" onclick="return gcashValue();" class="btn btn-default button button-small"><span>{l s='Ok'}</span></button>
<script type="text/javascript">
{literal}
function gcashValue() {
if ($.trim($("#Gcash_id").val()) == ''){
$("#Gcash_id").focus();
$("#errorBoxgcash").removeClass('hide');
$("#errorBoxgcash").html("Please enter GCash ID");
return false;
}
var gcashidVal=$('#Gcash_id').val();
//alert(gcashidVal);
$.ajax({
url:'{$base_dir}modules/loyalty/LoyaltyModule/gcashId',
type: 'POST',
data: 'ajax=true&gcashidVal='+gcashidVal,
success: function(response) {
alert(response);
console.log('success');
document.getElementById("Gcash_id").innerHTML=response;
}
});
return false;
}
{/literal}
</script>
我无法使用上述prestshop忠诚模块的ajax调用的url格式传递ajax请求,因此请给我正确的url格式,因为在firebug控制台的post请求错误截图中提到的错误,我在控制台进行ajax调用时得到错误
/public_html/测试/主题/pf_newfashionstore/模块/忠诚/视图/模板/前面/loyalty.tpl//public_html/测试/模块/忠诚LoyaltyModule.php
http://imgur.com/a/kspSi
试试这个
var fd = new FormData();
fd.append('ajax', true );
fd.append('gcashidVal', gcashidVal);
$.ajax({
url: '{$base_dir}modules/loyalty/LoyaltyModule/gcashId',
data: fd,
processData: false,
contentType: false,
type: 'POST',
success: function(data){
alert(data);
}
});
更多访问:如何在jQuery中使用ajax请求发送FormData对象?
在ajax对象中构造一个合适的URL。
url: baseUri + 'modules/loyalty/LoyaltyModule.php'
baseUri
是一个全局JavaScript变量,你可以在每个PrestaShop页面。