php - javascript works on localhost but fails on hosting server -
when click on add-to-basket button see error appears in browser console saying :
here basket.js file :
$(document).ready(function() { initbinds(); function initbinds() { if ($('.remove_basket').length > 0) { $('.remove_basket').bind('click', removefrombasket); } if ($('.update_basket').length > 0) { $('.update_basket').bind('click', updatebasket); } if ($('.fld_qty').length > 0) { $('.fld_qty').bind('keypress', function(e) { var code = e.keycode ? e.keycode : e.which; if (code == 13) { updatebasket(); } }); } } function removefrombasket() { var item = $(this).attr('rel'); $.ajax({ type: 'post', url: '/home/u919084925/public_html/mod/basket_remove.php', datatype: 'html', data: ({ id: item }), success: function() { refreshbigbasket(); refreshsmallbasket(); }, error: function() { alert('an error has occurred'); } }); } function refreshsmallbasket() { $.ajax({ url: '/home/u919084925/public_html/mod/basket_small_refresh.php', datatype: 'json', success: function(data) { $.each(data, function(k, v) { $("#basket_left ." + k + " span").text(v); }); }, error: function(data) { alert("an error has occurred"); } }); } function refreshbigbasket() { $.ajax({ url: '/home/u919084925/public_html/mod/basket_view.php', datatype: 'html', success: function(data) { $('#big_basket').html(data); initbinds(); }, error: function(data) { alert('an error has occurred'); } }); } if ($(".add_to_basket").length > 0) { $(".add_to_basket").click(function() { var trigger = $(this); var param = trigger.attr("rel"); var item = param.split("_"); $.ajax({ type: 'post', url: '/home/u919084925/public_html/mod/basket.php', datatype: 'json', data: ({ id : item[0], job : item[1] }), success: function(data) { var new_id = item[0] + '_' + data.job; if (data.job != item[1]) { if (data.job == 0) { trigger.attr("rel", new_id); trigger.text("remove basket"); trigger.addclass("red"); } else { trigger.attr("rel", new_id); trigger.text("add basket"); trigger.removeclass("red"); } refreshsmallbasket(); } }, error: function(data) { alert("an error has occurred"); } }); return false; }); } function updatebasket() { $('#frm_basket :input').each(function() { var sid = $(this).attr('id').split('-'); var val = $(this).val(); $.ajax({ type: 'post', url: '/home/u919084925/public_html/mod/basket_qty.php', data: ({ id: sid[1], qty: val }), success: function() { refreshsmallbasket(); refreshbigbasket(); }, error: function() { alert('an error has occurred'); } }); }); } // proceed paypal if ($('.paypal').length > 0) { $('.paypal').click(function() { var token = $(this).attr('id'); var image = "<div style=\"text-align:center\">"; image = image + "<img src=\"/images/loadinfo.net.gif\""; image = image + " alt=\"proceeding paypal\" />"; image = image + "<br />please wait while redirecting paypal..."; image = image + "</div><div id=\"frm_pp\"></div>"; $('#big_basket').fadeout(200, function() { $(this).html(image).fadein(200, function() { send2pp(token); }); }); }); } function send2pp(token) { $.ajax({ type: 'post', url: '/mod/paypal.php', data: ({ token : token }), datatype: 'html', success: function(data) { $('#frm_pp').html(data); // submit form automatically $('#frm_paypal').submit(); }, error: function() { alert('an error has occurred'); } }); });
i tried resolve couldn't find proper solution. me this, cannot understand cause of error.
this due rules of origins (cors), reason javascript(browser) sees request not residing in same server. , reason that, believe, because /home/u919084925/public_html/mod/basket.php not seen valid url on server, should start http://{hostname}/{path}.
Comments
Post a Comment