javascript - cross domain ajax call in chrome extension -


i making small extension test apis. while making ajax calls throughs error.

 refused load script 'http://localhost:8080/acton-demouser/user1?callback=jquery2210009971836116164923_1456851818933&format=json&_=1456851818934' because violates following content security policy directive: "default-src 'self' blob: filesystem: chrome-extension-resource:". note 'script-src' not explicitly set, 'default-src' used fallback. 

while ajax call url : http://localhost:8080/acton-demouser/user1

manifest.json :

{   "name": "ajax helper",   "version": "1.0",   "description": "my first chrome extension.",   "manifest_version": 2,   "browser_action": {     "default_icon": "icon.png",     "popup": "popup.html",     "default_popup": "popup.html"   },   "app": {     "background": {       "scripts": ["background.js"]     }   },   "icons": { "16": "icon.png", "128": "icon.png" },   "content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",   "permissions": [     "http://*/*"   ] } 

js file :-

$("form").submit(function(){     var ajaxtype = $('#request-method-selector option:selected').val();     var urlprefix = 'http://localhost:8080/acton-demo';     var url = $('#url').val();     if(ajaxtype === 'get'){         $.ajax({             url: (urlprefix+url),             error: function() {                     $('#error').html('<p>an error has occurred</p>');                 },             datatype: 'jsonp',             success: function(data) {                         $("#success").html(data);                     },             type: 'get'         });     }  }); 

what missing here.

you need specify 'http://localhost:8080' content_security_policy definition whitelist. because you're using 'jsonp' datatype @ calling endpoint $.ajax. is, not ajax calling, script tag creation. therefore, have add domain content_security_policy definition.

"content_security_policy": "script-src 'self' http://localhost:8080 https://ajax.googleapis.com; object-src 'self'", 

basically, can specify urls has 'https' prefix only. however, easy development, allows specify 2 domains 'http://localhost' , 'http://127.0.0.1'. described in document.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -