-2

I want to pass ajax request from themes folder/loyalty.tpl to /public_html/test/modules/loyalty/LoyaltyModule.php in prestashop 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>

I am not able to pass the ajax request using the url format of the ajax call of the prestashop loyalty module mentioned above So please give me the correct url format as the concerned to the error mentioned in the screenshot of post request error in the console of firebug I am getting error in the console when making ajax call from

/public_html/test/themes/pf_newfashionstore/modules/loyalty/views/templates/front/loyalty.tpl to /public_html/test/modules/loyalty/LoyaltyModule.php

http://imgur.com/a/kspSi
Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
Gerg
  • 11
  • 7

2 Answers2

0

try this one

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);
  }
});

for more visit : How to send FormData objects with Ajax-requests in jQuery?

Community
  • 1
  • 1
Pratik Bhalodiya
  • 736
  • 7
  • 14
0

Construct a proper URL in ajax object.

url: baseUri + 'modules/loyalty/LoyaltyModule.php'

baseUri is a global JavaScript variable available to you on every PrestaShop page.

TheDrot
  • 4,246
  • 1
  • 16
  • 26
  • Ok First I will create a voucher which gives 10% discount on the final amount of the product We are giving 5000 credit cash for each registered customer in our website...The customer can use the voucher until 5000 rupees got over.when the order got placed using the above mentioned voucher I want to display the discount amount deducted from the 5000 example for first order discount is 500(5000-500=4500 I should get ) for the first time of the voucher used For the second order using the same voucher discount suppose the discount amount is 400 amount should be (4500-400=4100) – G – Gerg Oct 03 '16 at 05:08
  • And what does this have to do with your original question? – TheDrot Oct 04 '16 at 18:00
  • I got the solution for the queries Thank you – Gerg Oct 05 '16 at 07:10