这里是我的C#代码:AJAX - 有不同的反应,取决于服务器的响应
if (!String.IsNullOrEmpty(bookRoom))
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1); //If we ever upgrade, its not that important but change this to the right version
//service.UseDefaultCredentials = true;
service.Credentials = new WebCredentials("MYNLJ", "", "");
service.Url = new Uri("http://DIR/EWS/Exchange.asmx"); //This is the EWS file
Appointment appointment = new Appointment(service);
String ITMtgMailboxToAccess = roomEmail; //Mailbox name
FolderId ITMtgCalendarFolderId = new FolderId(WellKnownFolderName.Calendar, ITMtgMailboxToAccess);
appointment.Subject = "Walk In Meeting";
appointment.Body = "Test Meeting";
double htoAdd = Convert.ToDouble(MeetingLength.SelectedItem.Value);
appointment.Start = DateTime.Now;
appointment.End = DateTime.Now.AddMinutes(htoAdd);
CalendarView Checkcv = new CalendarView(appointment.Start, appointment.End); //Don't change this
try
{
FindItemsResults<Appointment> ITMtgfapts = service.FindAppointments(ITMtgCalendarFolderId, Checkcv);
List<Appointment> ITMtgappointments = new List<Appointment>();
if (ITMtgfapts.Items.Count > 0) // If there is more than one item
{
在这里,我不想让Ajax请求知道订票不成功
// "Your booking will conflict with another appointment";
}
else
{
让AJAX要求知道它是成功
//Success
appointment.RequiredAttendees.Add(roomEmail);
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
}
}
catch
{
}
}
AJAX代码:
<script type="text/javascript">
$(function() {
$('#BookButton').click(function (event) {
var form = $('#Form1');
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: $("#BookRoom :input").serialize()
}).done(function() {
// Optionally alert the user of success here...
$('#BookRoom').modal('hide');
$('#SuccessMsg').text('Meeting Booked');
$('#SuccessMessage').modal('show');
setTimeout(function() { $('#SuccessMessage').modal('hide'); }, 3000);
}).fail(function() {
// Optionally alert the user of an error here...
alert("Error submitting AJAX request");
});
event.preventDefault(); // Prevent the form from submitting via the browser.
});
});
呃...?那么你的问题是什么?我真的不喜欢通过你的代码拖网来试图提出一个诚实的问题! – Belogix
@Belogix问题是我如何从C#发回响应给AJAX基本上。 –