The way I see it, I can create `form` or `a` elements, decorated with the data attributes. The unobtrusive script listens for form submit and anchor click events. There is no way to interact with the internals of the script.
I would like to ask for the following feature. I would like to trigger the `asyncRequest` function from my JavaScript code. `AjaxOptions.ToUnobtrusiveHtmlAttributes()` is luckily public, so I can for example create a `div` or anything and decorate that. Then I could implement any logic and do an ajax call without user interaction.
Also, less important to me, but it would also be nice to enable other elements, not just anchors. For example images, buttons, or anything. I understand that the `form` submit handler is a special case, but if you look at the code of the anchor handler, it goes straight to `asyncRequest`. It is a bit redundant because if you enable calling `asyncRequest` from outside, then of course I can glue any kind of user event to call it.
Comments: So `asyncRequest` is private. The anchor handler looks like this: $(document).on("click", "a[data-ajax=true]", function (evt) { evt.preventDefault(); asyncRequest(this, { url: this.href, type: "GET", data: [] }); }); What I would like is something like this added to `jquery.unobtrusive-ajax.js` so that I can call `asycnRequest` without user interaction: window.unobtrusiveAjax = { executeAjax: function(element, optional_url, optional_type, optional_data) { asyncRequest(element, { url: optional_url, type: optional_type || "GET", data: optional_data || [] } } }; Only the element would be mandatory, URL is optional because there is also a data-attribute for that which can override the URL of anchors and forms, type and data parameters have sensible defaults. You could even make it so that I could just call `$(element).executeUnobtrusiveAjax()`.
I would like to ask for the following feature. I would like to trigger the `asyncRequest` function from my JavaScript code. `AjaxOptions.ToUnobtrusiveHtmlAttributes()` is luckily public, so I can for example create a `div` or anything and decorate that. Then I could implement any logic and do an ajax call without user interaction.
Also, less important to me, but it would also be nice to enable other elements, not just anchors. For example images, buttons, or anything. I understand that the `form` submit handler is a special case, but if you look at the code of the anchor handler, it goes straight to `asyncRequest`. It is a bit redundant because if you enable calling `asyncRequest` from outside, then of course I can glue any kind of user event to call it.
Comments: So `asyncRequest` is private. The anchor handler looks like this: $(document).on("click", "a[data-ajax=true]", function (evt) { evt.preventDefault(); asyncRequest(this, { url: this.href, type: "GET", data: [] }); }); What I would like is something like this added to `jquery.unobtrusive-ajax.js` so that I can call `asycnRequest` without user interaction: window.unobtrusiveAjax = { executeAjax: function(element, optional_url, optional_type, optional_data) { asyncRequest(element, { url: optional_url, type: optional_type || "GET", data: optional_data || [] } } }; Only the element would be mandatory, URL is optional because there is also a data-attribute for that which can override the URL of anchors and forms, type and data parameters have sensible defaults. You could even make it so that I could just call `$(element).executeUnobtrusiveAjax()`.