0

I have a php form, submitting using AJAX. The form has multiple submit buttons, the server side is not able to understand which button is clicked.

How to pass the information of the inputType="submit" button clicked to the server side using AJAX?

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
Winter
  • 341
  • 1
  • 4
  • 8
  • this might help: http://stackoverflow.com/a/1200312/6582942 – pravindot17 Jan 19 '17 at 07:10
  • Take a look at the click event. With whatever you are using to capture the click, write the event to console.log(). In there you will have access to the element, and then could get an ID or some other attribute to pass along with the AJAX payload. – Adam Hopkins Jan 19 '17 at 08:32
  • use same class for button and make different ids whenever you hit the button use `$(this).attr('id')`. – Bugfixer Jan 19 '17 at 09:14
  • You need to provide a [mcve] demonstrating the problem. I can think of a few basic approaches to solve this type of problem, but which are appropriate would depend on the existing code that they would have to interact with. – Quentin Jan 19 '17 at 09:16

1 Answers1

-1

You can have name for buttons.

input type="submit" name="submit_1"

Then you can check the name exist in your payload.

masterFly
  • 1,072
  • 12
  • 24
  • This would work for a regular form submission, but the question says they are using Ajax. – Quentin Jan 19 '17 at 09:12
  • What is the difference that the endpoint see if we make a regular POST OR a AJAX POST? If we are making a POST request. It is same!! – masterFly Jan 19 '17 at 10:50
  • — You *can* construct identical requests using a regular form an Ajax, but the contents of the JavaScript version will depend on what the JavaScript does. The various standard functions used to generate a request body for Ajax using "all of a form" will ignore submit buttons. – Quentin Jan 19 '17 at 11:19