开发者

Clicking a simple HTML button to write into DB via jQuery / Javascript & PHP

开发者 https://www.devze.com 2023-04-03 03:40 出处:网络
This may be a simple and stupid question, yet I am going ahead and asking. -----------HTML--------- <input ty开发者_如何学编程pe=\"button\" value=\"Yes\" class=\"Y\" id=\"Yes\">

This may be a simple and stupid question, yet I am going ahead and asking.

-----------HTML---------

<input ty开发者_如何学编程pe="button" value="Yes" class="Y" id="Yes">
 <input type="hidden" value="x1" id="a1" name="a1">


-----------JQUERY--------------

$('#RYes').click(function() {

            });

When I click on #RYes, it must save the value of #Yes and #a1 into the db. Can I write javascript into the jquery code shown above. I am using PHP/ JavaScript


You can do it without ajax, and without complete page reload, using an iframe. But that of course depends on your overall structure of your site. To do it with an iframe just make it into a form and change type of the button to submit as Tyler Kiser describes.


You should be able to write and ajax call to a php page that runs the queries to save your values to the database. more info on the post method here http://docs.jquery.com/Post


You can do it by having a backend php script which can take these values from a POST request.

Then you could submit there values from your click function using an AJAX call. like:

$.post('your_backend.php', {'Yes' : $('#Yes').val(), 'a1' : $('#a1').val()}, function(data){});

And you can write some handler code for once the POST operation is complete in the callback function

0

精彩评论

暂无评论...
验证码 换一张
取 消