1

i am trying to call a page using javascript but insted of getting response i get the following error

$.ajax({
    type: "POST",
    url: "https://account.domain.com/testimonial/user_message",
    success:function(res){

        alert(res);

    }

});

when i call this code i am getting an error in console

XMLHttpRequest cannot load https://account.domin.com/admin/testimonial/user_message. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://domain.com' is therefore not allowed access.

if i put this url into the browser then it show me the result but if i call this using jquery then why i am getting this error and how can i call this url

user3713959
  • 101
  • 1
  • 13
  • Take a look at [this question](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource?lq=1) and [this one](http://stackoverflow.com/questions/20059658/xmlhttprequest-cannot-load-no-access-control-allow-origin-header-is-present-o) – Regent Aug 16 '14 at 18:31

3 Answers3

2

Modern browsers block cross domain XMLHttpRequest. Please follow this link for more information about how to do XMLHttpRequest to different domains.

sadrzadehsina
  • 1,331
  • 13
  • 26
2

use this code instead

url: <?php echo site_url('testimonial/user_message');?>
//it will automatically get your base url and append your parameter in site_url.
CodeSlayer
  • 1,318
  • 1
  • 12
  • 34
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Ravimallya Aug 18 '14 at 06:19
  • he's asking why the XMLHttpRequest cannot be loaded so i suggested this code, cause in code igniter, it's hard to use url since it has alot of folder. – CodeSlayer Aug 18 '14 at 06:25
  • If you're answering a question, please be more specific and explain your answer, so that it will be helpful to others also. – Ravimallya Aug 18 '14 at 06:28
0

I believe this code might help you solve your troubles.

url: <?= site_url('testimonial/user_message');?>