This has been rattling my brains for 2 days now, and without any luck I thought I would ask here. The problem I'm having is that after getting a string from a ajax request and saving it to a variable, the alert shows correctly "1/2/3/4" however when i split by using var array = variable.split('/');
and try and access the array content it only shows that the array length is 1 and that one is blank. Have used an alert before the string to ensure that the string is holding the required content. Any help would be appreciated.
My code is as followed:
HTML:
var Cid = calEvent.Cid;
$(".titleU").val(calEvent.title);
$('.startDateU').val($.fullCalendar.formatDate(calEvent.start, "yyyy-MM-dd HH:mm"));
$('.endDateU').val($.fullCalendar.formatDate(calEvent.end, "yyyy-MM-dd HH:mm"));
$(".descriptionU").val(calEvent.description);
$(".clientU").val(calEvent.clientName);
$(".workOrderU").val(calEvent.workOrderID);
$(".jobLocationU").val(calEvent.eventLocation);
// For loop for adding employee to update panel
var workOrderEmployeesA = ""; // Update form
$.ajax({
type: "POST",
url: "<?php echo base_url('scripts/phpScripts/getEmployeesCID.php');?>",
data: {Cid: Cid},
datatype: "html",
success: function(json){
workOrderEmployeesA = $.trim(json).substring(0, json.length -1);
alert(workOrderEmployeesA);
}
});
var workOrderEmployeesB = workOrderEmployeesA.toString().split('/');
for(var i=0;i<workOrderEmployeesB.length;i++){
alert(workOrderEmployeesB[i]);
}
PHP:
$result = mysqli_query($con,"SELECT * FROM employeeCalendar WHERE CalendarID='$_POST[Cid]'");
$counter = 0;
while($row = mysqli_fetch_array($result)){
echo $row['EmployeeID'];
if($counter == mysqli_num_rows($result)){
}else{
echo "/";
}
$counter++;
}
mysqli_close($con);
The following code works correctly, but not sure how its different in any way that would prevent proper functionality.
var workOrderEmployeesB = "1/2/3/4/5".split('/');
for(var i=0;i<workOrderEmployeesB.length;i++){
alert(workOrderEmployeesB[i]);
}
This is probably something silly that I've over looked, Any suggestions would be much appreciated.
Thank-you in advance,
Chris