views:

138

answers:

3

In my chrome extension I call this:

jsonPost = {
    email:"[email protected]",
    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 makes it to the server. But the response is lost, in the console ---type of data = String ---data in function =

So for some reason I am not getting the response back. Works from the browser. I even tried doing a get against cnn.com and got no response.

any ideas?

thanks

+1  A: 

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

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

}, 'json');
Puaka
+1  A: 
T.J. Crowder
+1  A: 

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

Matt Gibson
it wasn't the ,"json" (which I'd tried). It was a permissions issue. In the manifest.json I put this in and it worked: "permissions": [ "tabs", "http://*/" ],Actually I wanted http://localhost:3000/ in there, but that didn't seem to work. But that's just my test env so I don't really care for now...
phil swenson