Mixed content issue - insecure XMLHttpRequest endpoint

混江龙づ霸主 提交于 2019-12-10 11:39:51

问题


I am facing Mixed content issue when i browse my site in HTTPS. I am calling API from jQuery, and I haven't mentioned the protocol, so assuming browser should pick the same protocol with site browsed (http or https). My jquery code looks like below:

$.get("/api/Product/GetMore", { pageIndex: currentPage })
    .done(function(result) {
    .....

It works fine (able to get the result from API call) when browsed the site in http and do the required action to get the result. But when I browsed the site and try to get the result in https, i am getting below error in browser console. Same thing happens even if i hard-code the complete API url with https protocol. Mixed Content: The page at 'https:///product' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http:///api/product/getmore?pageIndex=1'. This request has been blocked; the content must be served over HTTPS.

XHR failed loading: GET "https:///api/Product/GetMore?pageIndex=1".

Please let me know if you have any solution.

Thanks, Sharath


回答1:


in order to work you need to specify index.php so it knows which function it is calling. Because this is similar to cUrl call it requires full path. And to let call to decide which protocol it is on, you need double slashes at the beginning. So try this:

$.get("//api/Product/GetMore/index.php", { pageIndex: currentPage })

OR

$.get("//api/Product/GetMore/", { pageIndex: currentPage })

Fixed my issues in the past.



来源:https://stackoverflow.com/questions/34172075/mixed-content-issue-insecure-xmlhttprequest-endpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!