Skip to content
Advertisement

Why doesn’t my program enters in my switch case “deleteRegistro” sending and getting with $_POST in PHP?

My problem: I don’t know why, my switch case is doesn’t working properly and I don’t know why if my AJAX status == 'succcess'.

My onClick function is in my button:

JavaScript

My function:

JavaScript

My switch case:

JavaScript

As you can see, my AJAX status == 'succcess':

enter image description here

This is my full code if you need to check it:

JavaScript

Can someone give me a hand? I really don’t understand.

If the status == 'success', it means that the POST request has been sent successfully, so I should go into my case switch and print a “Hello!”.

What am I doing wrong?

Advertisement

Answer

You haven’t mentioned in the question where the switch case is on, I assume its in <?=SITE_URL_ADMIN?>/alexcrudgenerator/crud/res/" index.php file ok?

So you are posting the data to a php file using Ajax and Ajax successfully posts the data, but how come you can expect that hello to be displayed on the screen?

As I have mentioned in my previous answer the output of the php file where switch case exist will not be displayed, $.post method just posts the data to the file it won’t redirects to the file.

for your need I suggest you to use the hidden form to post the data to the file.

Modified delete function would be..

JavaScript

Now add a form deleteform in html code note:- add before you use this script for function Delete()

JavaScript

After this form get submit you will be entering to your php file in the given URL, here you can do whatever you want play with the data you got from post method.

If you don’t want to redirect to you php file containing switch case just display data you got from the page.

JavaScript

Now you can see what is the response of the file in console, in your case it should show you hello as you haven’t echoed anything else.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement