Jquery send data to php without ajax

How can I do this without a love of ayaktika? I need to debug a nasty php script. There is no form, but only an image that, when pressed, brings up the following.

$.post("php/navTabs.php", { action: "deleteTab", theHTM: thehtm }, function(jdata) { alert("The tab was " + jdata.is_deleted); }, "json"); 

Thanks again, Todd

0
source share
3 answers

Short answer: you cannot use Javascript.

Long answer:

If you want to avoid using AJAX, you have two options:

1) Make the image a part of the form and send hidden inputs when you click the button.

  <form method="form.php" action="post"> <input type="hidden" name="action" value="delete"/> ...rest of form... </form> 

2) Make the image a link with inputs tied to a URL. How:

  form.php?action=delete 

Not sure why you want to avoid using AJAX.

-1
source

I would change the $ _POST variables in php / navTabs.php to $ _GET and access the script just like

 php/navTabs.php?name=value&name2=value2 etc 

This way you have no ajax in your way.

+2
source

This method will allow you to use a stream very similar to $.post() , since it works transparently with the user and includes a callback function:

 <img /> <iframe id="workFrame" style="display: none"></iframe> <form action="php/navTabs.php" target="workFrame" method="post" style="display: none"> <input type=hidden id="hidden-1"> <input type=hidden id="hidden-2"> </form> <script> $('#hidden-1').val('some value to send to the server'); $('#hidden-2').val('some OTHER value to send to the server'); $('img').on('click', function () { $('form').trigger('submit'); }); </script> 

It uses a form with hidden inputs (so it may be transparent to the user). You can set the value of the hidden inputs using JavaScript, and then programmatically submit the form to a hidden iframe.

Another feature of this method is that you can bind to the load event for the iframe and have a callback function, as in $.post() :

 $('#workFrame').on('load', function () { var response = $(this).contents().filter('body'); //if you output JSON in your PHP  you could parse this as JSON and do work }); 

UPDATE

If all you want to do is see the result from your PHP script, then you can use your developer tools (FireBug, etc.) to view the response. You can also register the response in an AJAX callback:

 $.post("php/navTabs.php", { action: "deleteTab", theHTM: thehtm }, function(jdata) { alert("The tab was " + jdata.is_deleted); console.log(jdata); }, "json"); 

If you are not currently using Dev. Tools with a console, I highly recommend checking out FireBug , this will save you an amazing amount of debug time code.

+1
source

Source: https://habr.com/ru/post/1258644/


All Articles