Within our website we are dynamically injecting the HTML of a contact form on our pages.
I.e. a div similar to <div form-src="formhtml.html?param1=blahblahblah" form-submit="../formSubmissionendpoint"></div>
has its attributes removed, an AJAX call is made to form-src
to get the HTML and that HTML is placed within the div.
I am in complete control of the HTML (the actual form) that the AJAX call pulls in and can modify it with JS as needed.
The data-src
attribute normally has a URL query string that we use to grab some information from a backend database ie blahblahblah. The AJAX call does include this query string when it gets the HTML form.
Is there anything I can do from the HTML form I have control over to get the query string parameters for this request? I feel like this should be so simple but I don't work in javascript and feel out of my element here. Originally I thought something like window.location.href but instead of for the window the ajax request.
Thanks to any help anyone can provide!
Some clarification code: <div data-role="form" form-src="htmlform.html?param=blahblahblah" form-submit="../SaveFormData/Endpoint"></div>
$formContainers = $('[data-role=form]');
_url = $formContainer.attr('form-src');
_suburl = $formContainer.attr('form-submit');
var UrlParts = _url.split("?"); //This is the value I need
$.ajax({
url: _url,
context: document.body
}).done(function (form) {
_form = $(form).filter('form').prop('outerHTML');
$formContainer.html(form);
...
Aucun commentaire:
Enregistrer un commentaire