Paste into MySql database from Javascript window?

Merry Christmas is all.

I have a calendar (main page) which, when a user clicks a date, opens a window (booking window) in the calendar using javascript showing another php page that has a booking form (booking page). I have a javascript check on the main page and everything works fine.

I don’t know if the sherry is too strong or just my mind for Christmas, but I can’t figure out how to do it.

When the user clicks the submit button, the whole page is updated, as on the server side, but I'm not sure what I need to do so that only this window is updated instead of the whole page.

Is there any other way besides using Javascript to enter data on MySql? I am lost.

Thank you in advance:)

EDIT JAVASCRIPT CODE: -

var date = (thisId.id);
var hr = new XMLHttpRequest();
var url = "Scripts/NewBooking.php";
var vars = "date="+date+"&jobtime="+jobtime;
var jobtime = "Morning";
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
    if(hr.readyState == 4 && hr.status == 200) {
        var return_data = hr.responseText;
        document.getElementById("events").innerHTML = return_data;
    }
}
hr.send(vars)
document.getElementById("events").innerHTML = "processing...";
+4
1

, AJAX . AJAX :

  • -
  • -
  • -
  • -

:

$('#button').on('click',function(){
    $.ajax({
        url :'<?php echo site_url("your link goes here"); ?>',
        type: "POST",
        data : {
            your_data : some_data
        },
        success: function(data)
        {
            alert('success');
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(xhr.responseText);
            alert(thrownError);
        }
    }); 
});
+2

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


All Articles