I have a form with a variable size (length) that is populated from MySQL db. There are 4 fields that make up the information used to create the button (id, button #, name and price). When the form is submitted, I want to save all the values ββin the MySQl database and update the div at the bottom of the page with a success message. For all my other pages, I used something like ...
xmlhttp.open("GET","myfile.php?a="+val1+"&b="+val2+"&c="+val3+"&d="+val4,true); xmlhttp.send();
PHP files save data and generate a message for the div. and write in a div ...
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
This works well for all my other pages, but since I donβt know how many fields there will be, I cannot hardcode the xmlhttp.open instruction.
I am new to ajax and jQuery and I know that there must be a way to make this easy, but I have not been able to do anything. I was told that I can use this
$.each($('#yourform').serializeArray(), function() { console.log(" <" +this.name+ '>' + this.value + "</" + this.name + "> " ); });
and it prints out every element of the form, but is not sure how to get this information in my PHP file and how to create a return message for the div. I'm new to ajax and jquery again, so if I could get some explanation, I'm sure this will help me figure this out.
source share