• Lỗi: No 'Access-Control-Allow-Origin'

  • Thông báo lỗi bạn gặp và mọi người giúp fix.

Thông báo lỗi bạn gặp và mọi người giúp fix.
 #5046  by MacKen
 12 Feb 2019 11:21
Mình đang sử dụng javascript ở phía domain B.
Cần tích hợp với các dịch vụ không hoàn toàn nằm trong tầm kiểm soát của domain A.
Đã phải đối mặt với thông báo lỗi này trong bảng điều khiển trình duyệt của domain A


Mình có đoạn script gắn trong code php trên vpssim như sau :
Code: Select all
function dtv_phanmemxaydung(){ echo '<script>
;(function($){
/* Phan mem du toan cong trinh */
$("#tracuu").click(function(){
 congtrinh = $("#congtrinh").val();
 goixaydung = $("#goixaydung").val();
 dientich = $("#dientich").val();
 sotang = $("#sotang").val();
 $.post("https://www.diathevang.com/wp-content/plugin/phanmemxaydung/plugins-dutoancongtrinh.php",{congtrinh:congtrinh,goixaydung:goixaydung,dientich:dientich,sotang:sotang},function(data){
   if(data==\'congtrinh\')
   {
      $(".dutoan_ct").html("<span class=\'fl w100f top10\' style=\'padding-top: 10px; border-top: 1px solid #FFFB83;\'><i class=\'fa fa-exclamation-triangle\'></i> Xin vui lòng chọn loại công trình!</span>");
      $("#congtrinh").focus();
   }else if(data==\'goixaydung\')
   {
     $(".dutoan_ct").html("<span class=\'fl w100f top10\' style=\'padding-top: 10px; border-top: 1px solid #FFFB83;\'><i class=\'fa fa-exclamation-triangle\'></i> Xin vui lòng chọn gói xây dựng!</span>");
      $("#goixaydung").focus();
   }else if(data==\'dientich\')
   {
     $(".dutoan_ct").html("<span class=\'fl w100f top10\' style=\'padding-top: 10px; border-top: 1px solid #FFFB83;\'><i class=\'fa fa-exclamation-triangle\'></i> Xin vui lòng nhập diện tích!</span>");
      $("#dientich").focus();
   }else if(data==\'sotang\')
   {
     $(".dutoan_ct").html("<span class=\'fl w100f top10\' style=\'padding-top: 10px; border-top: 1px solid #FFFB83;\'><i class=\'fa fa-exclamation-triangle\'></i> Xin vui lòng chọn số tầng!</span>");
      $("#sotang").focus();
   }else
   {
       $(".dutoan_ct").html(data);  
   }
 });
});
})(jQuery);
</script>';
}
Sau khi get dữ liệu thì thấy báo lỗi:

XMLHttpRequest cannot load https://www.diathevang.com/wp-content/p ... gtrinh.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.diathevang.vn' is therefore not allowed access.


Đã làm nhìu cách nhưng ko được ... QUa đây anh em nào có kinh nghiệm xin chỉ giáo .. Thanks
Get 25 USD Free To USE VPSSIM