Logo
My Account |  Site Map | Contact Us  
Welcome Guest Search | Active Topics | Sign In | Register

HOWTO - Capture posted data from Ajax post with RegisterCustomSchemes/ResourceHandler. Options
JSB
Posted: Friday, July 21, 2017 4:35:00 PM
Rank: Advanced Member
Groups: Member

Joined: 1/2/2017
Posts: 32
Please help,

How can one post data to a custom resource handler using Ajax?
I'm trying to capture posted data from an Ajax call in rendered HTML.jQuery script on a EO.WebBrowser control, where I am using a custom resource handler.
My custom resource handler follows the sample from here: https://www.essentialobjects.com/doc/webbrowser/advanced/resource_handler.aspx
I have a simple Ajax call as such:

$.ajax
({
url: "sample://MyHandfler/MyApi",
type: "POST",
dataType: "json",
data: JSON.stringify({ Action: "Test" }),
contentType: "application/json; charset=UTF-8"
});

My handler gets called successfully, but the posted data in the "EO.WebBrowser.Request" parameter passed to the overridden "ProcessRequest" function is not getting through.
Its "PostData" data member always has 0 entries (Count = 0).
The source of the POST is an ajax call from the rendered HTML.
eo_support
Posted: Monday, July 24, 2017 11:44:13 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 23,072
Hi,

You would just use the standard HTTP protocol instead of your own "sample" protocol for this case.

HTTP POST is for HTTP/HTTPS protocol only. So you won't be able to use "sample" protocol and HTTP post at the same time. Intercepting standard HTTP protocol is almost exactly the same as intercepting a custom "sample" protocol --- except that you don't need to call RegisterCustomSchemes. So it's even easier.

You can use your own special Url to mark your own special request. For example, you can use "http://myhandler/myapi" and then match that Url in your custom resource handler's Match function. For any other "normal" Url, you can just return false from your Match function and the default behavior will kick in.

Thanks!
JSB
Posted: Monday, July 24, 2017 2:50:51 PM
Rank: Advanced Member
Groups: Member

Joined: 1/2/2017
Posts: 32
Thanks for the reply. This seems to work. However, I've bumped into other issues, for which I'll make another post.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.