I am trying to see how I can pass a dynamic input type through serialize and be processed in my ajax php page for return via json. As you see, it is made up of a for loop which increments each input based on a slider. I cannot just process id=”BRV-brtrv-boxamount- because it dosen’t recognise it. I would be grateful if someone could help me with this. Thanks
for(var i = 0;i < $(this).val();i++) {
$("#BRV-brtrv-boxnumber").append('<div data-role="fieldcontain"><label for="BRV-brtrv-boxamount" class="ui-input-text">Enter box ' + (i + 1) + ' number:</label><input type="text" name="BRV-brtrv-boxamount-' + i + '-no" id="BRV-brtrv-boxamount-' + i + '-no" class="BRV-brtrv-boxamount ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-a" required="required" /></div>')
}
+++EDIT+++
$(function() {
$("#BRV_brtrv").submit(function() {
var send = $(this).serialize();
$.ajax({
type: "POST",
url: "boxrtrvajax.php",
cache: false,
data: send,
dataType: "json",
success: function (msg) {
$('#brtv-result').addClass("result_msg").html(msg.service);
},
error:function (xhr, ajaxOptions, thrownError){
jAlert('There was an exception thrown somewhere');
alert(xhr.status);
alert(thrownError);
}
});
return false;
});
});
since you provided a complete exemple, here is the complete answer:
but your example shall work too. note: you can use $.post() instead of $.getJson() (or even $.get(), as both $.get and $.post are able to recognize and parse json response if there is one).