I am trying to get the data from the Web Service by using the POST Method.
This is my javascript to get the data
var s = {
OpportunityID: 6
}
$.ajax({
type: "POST",
url: "/ws/WSServices.svc/GetStudentTimeTableByOpportunityID",
data: JSON.stringify(s),
contentType: "application/json",
dataType: "JSON",
async: false,
success: function (data) {
console.log(data);
}
});
Here is my Server Side code
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat= WebMessageFormat.Json)]
public List<DataEntity.CalendarEvent> GetStudentTimeTableByOpportunityID(int OpportunityID)
{
Utils.Debug("InWebService : " + OpportunityID);
List<DataEntity.CalendarEvent> events = new List<DataEntity.CalendarEvent>();
//populate events code
return events;
}
The problem is that it is not running even the first line of code and always showing that there is a Bad Request (400). Please see the screenshots in FireBug
I checked it and it shows the correct data in JSON format and I couldn't figure out why it is showing as 400 Error.
Please help me to highlight how I could invoke the Post Request to WCF Webservices by using JQUERY AJAX.