In a DNN 4.9.2 web site ,I am trying to call a server side method using jquery. I am setting a Request Header "X-OFFICIAL-REQUEST" in following code. JavaScript Code ...
jQuery.ajax({
type: "POST",
async: "false",
url: location.href,
dataType: "json",
data: ({'FUNCTION': 'FunctionName', 'param0': '1' }),
success: function(data) {
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
},
beforeSend: function(xhr) {
xhr.setRequestHeader("X-OFFICIAL-REQUEST", "TRUE");//Used to ID as a AJAX Request
},
complete: function(XMLHttpRequest, textStatus) {
}
});
While in the Code behind I am processing the request
Response.Write(strData)
Response.Flush()
On Response.Flush
I am getting error "Server cannot append header after HTTP headers have been sent."
Code Behind...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Request.Headers("X-OFFICIAL-REQUEST") Is Nothing Then
If Request.Headers("X-OFFICIAL-REQUEST").ToString().ToLower() = "true" Then
AjaxWrapper()
End If
End If
End Sub
Protected Sub AjaxWrapper()
Response.Clear()
Dim strData As String = String.Empty
Dim type As Type = [GetType]()
Dim method As MethodInfo = type.GetMethod(Request.Params("FUNCTION"))
Dim objs As Object() = New Object(method.GetParameters().Length - 1) {}
For i As Integer = 0 To objs.Length - 1
objs(i) = (New PortalSecurity()).InputFilter(Request.Params("param" & i), PortalSecurity.FilterFlag.NoMarkup)
Next
If method IsNot Nothing Then
strData = method.Invoke(Me, objs) 'This method is returning a test Message fr eg. Test Data
End If
Response.Write(strData)
Response.Flush()
Try
Response.Close()
Catch
End Try
Response.End()
Return
End Sub