Reputation: 606
I'm trying to send data from my chrome extension to my .net application using ajax. I'm using background script
to send data. Currently i'm unable to get data at my server. I guess there's issue in setting up manifest for chrome. However, how can i post data from chrome extension
?
Suggest any other alternatives if possible.
Thank you.
Upvotes: 0
Views: 890
Reputation: 77523
There is a specific mechanism in Chrome for communication with local applications: Native Messaging.
There is an important limitation to keep in mind: Chrome cannot talk to an already-existing process; it can only start a new one and talk over STDIO.
So you may need to have a "proxy" process that Chrome can start, which will connect (somehow, but no longer restricted in methods) to your main app and relay data.
Upvotes: 0
Reputation: 24008
You can send data to the server using XHR, or use jQuery.ajax() if you prefer. The end point will be the web service you have defined on the server. Check out this example, which uses jQuery for it.
For posting data, you pass all the data you want from the client in JSON format. You can use JSON.stringify() to convert your JavasScript object to a JSON string. If your object matches an entity structure on the server, it should automatically populate it, allowing you to specify that entity as the parameter of the web method. Otherwise, you can accept an object
parameter and extract the data from that.
In a Chrome extension, make sure you have the correct cross-origin permissions.
Upvotes: 1