JQuery / Ajax dialog where select between all rows of a sql table

in my CMS, I have a large table that is stored in all client companies. In the table PositionI want to save the idclient.

I have a page addPositionthat should allow you to insert this idchoice of client name. The way I thought to develop it is a popup dialog from which the entire list of clients is selected, and the result of the dialog should then be stored in a hidden field (for example).

Can i use jQuery or ajax? If so, how? If not, what is a good workaround (or perhaps a better solution) to the problem?

PS Part of PHP should not be a problem.

+5
source share
1

, AJAX jQuery, :

HTML:

<div id="message" style="display:none"></div>

<form action="script.php" method="post" id="myForm">
    <select name="employees">
        <option value="1">Joh Smith</option>
        <option value="2">Janeh Doe</option>    
    </select>
</form>

JQuery

$('#myForm').on('submit', function() {
    var $this = $(this);
    $.ajax({
        url: $this.attr('action'),
        type: $this.attr('method'),
        data: $this.serialize(),
        dataType: 'json',
        success: function(response) {
            if(response.success) {
                $('#message')
                    .text('Database updated successfully')
                    .addClass('success')
                    .show();
            }
            else {
                $('#message')
                    .text('Error happened, AJAX request completed but PHP had a problem.')
                    .addClass('error')
                    .show();
            }            
        },
        error: function() {
            alert('Error happened, AJAX request could not be completed.');
        }
    });
    return false;
});

PHP, :

echo json_encode(array(
    'success' => true
));

:

echo json_encode(array(
    'success' => false
));
+1

All Articles