Pushing jquery call inside chrome extension

In my chrome extension, I am calling this:

jsonPost = {
    email:"phil@demo.demo",
    password:"demo",
    content: $('#selected_text').val(), 
    notification_type: $('#notification_type').val(),
    name:$('#notification_name').val()
}

$.post('http://localhost:3000/api/create.json', jsonPost, 
        function (data) {
            console.log("type of data = " + typeof(data));
            console.log("data in function = " + data);
            }

      

The data is sent to the server. But the answer is lost, in the console --- data type = string --- data in function =

So for some reason I am not getting an answer. Works in a browser. I even tried to do against cnn.com and got no response.

any ideas?

thanks

+2


a source to share


3 answers


Are you using cross-site scripting restrictions? If it works on a page located on "localhost" but not on an extension, you may need to ask Chrome permissions to access things outside of the extension's default security context. See if Google's advice on requesting cross-origin permissions for an extension helps .



+1


a source


you need to use json as post type, for shorthand method use it like this



$.post(url, data, function(result) {

}, 'json');

      

+1


a source


jQuery will have a "better guess" on how to interpret the data based on the MIME type and some other factors, could that be wrong? You can force it to add a fourth parameter to your call by specifying the datatype - eg "json", "text", "html" ... Full list here in the docs ajax

.

+1


a source







All Articles