0

I'm try to add the return value of my php file to a title attribute. The correct data is return from the php file but for some reason 'appointmentData' is null. I have tried appointmentData.value and .innertext, but none of these work. ideas anyone? The value of appointmentData is "Id = 1 - Name = Blah"

var xmlhttp = new XMLHttpRequest();

        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                appointmentData = xmlhttp.responseText;
            }
        }

        xmlhttp.open("POST", "getBookedAppointmentDetails.php?".concat(dataString));
        xmlhttp.send();

        $(this).attr('title', appointmentData);

I have edited my code to use the follow ajax request:

 $.ajax({
            type: "GET",
            url: "getBookedAppointmentDetails.php",
            data: dataString,
            success: function (response){
                appointmentData = response;
                alert(appointmentData);
                $(this).prop('title', appointmentData);
            }
        });

I have inserted an alert to test the value of appointmentData, and this works fine. However, I'm till having problems assignment an attr/prop (tried both) to the element. Any ideas?

japes Sophey
  • 487
  • 3
  • 8
  • 26

1 Answers1

0
var appHover = $(this);

        var dataString = ("appDate=").concat(appDate).concat("&").concat("appTime=").concat(appTime).concat("&").concat("doctorId=").concat(doctorId);

        $.ajax({
            type: "GET",
            url: "getBookedAppointmentDetails.php",
            data: dataString,
            success: function (response){
                appHover.attr('title', response);
            }
        });
japes Sophey
  • 487
  • 3
  • 8
  • 26