passing form data to mySQL through AJAX

前端 未结 2 1832
故里飘歌
故里飘歌 2021-01-24 20:56

I am using JavaScript and AJAX to send form data to a php processing file to then populate an SQL database without refreshing the initial form page.

The php/SQL connec

2条回答
  •  爱一瞬间的悲伤
    2021-01-24 21:32

    Were it me i would just make this easier on myself by using the Form plugin. Its already got an ajaxSubmit set of functions to make ajaxify your form with little effort. IT also has the handy formSerialize function which will serialize a form for ajax submission or to append to a query string for a link. :-)

    That said an easier way without the plugin and utilizing your existing code:

    $("#form_process").click(function() {
    
      $.ajax({
        type: "POST",
        url: "**ABSOLUTE URL TO PROCESSOR**",
        data: {
          'choice': $("input[@name=RadioGroup1]:checked").val(), 
          'comments':  $("#comments").val()
        }
      });
    
    });
    

    Either way though, you also need to change all your radio inputs to have unique ID's (or no ID at all)... you cant use the same one as its required that all id attributes have unique values within the document.

提交回复
热议问题