I have a form, when the submit button is clicked I want to intercept the data and send it to an API. This code sends the first parameter, the Id, but none of the others.
$('#myForm').submit(function (e) {
e.preventDefault();
$('#myForm').children('input').each(function () {
$.get("/thisismyapiurl/", { Id: $('#dropdown').find(":selected").val(), paramName: this.Name, paramValue: this.Value });
});
});
So the URL is generates is /thisismyapiurl/Id without the other two values. I want it to be /thisismyapiurl/Id/Name/Value
Why is it only sending the first parameter, what can I change so it sends all of them?
2
Answers
Try to use jQuery to get name and value of your inputs:
Try
$(this)
instead ofthis
and.attr('name')
: