ASPX templates
Version 6.x > ASPX templates > jQuery AJAX can't find code behind function. View modes: 
User avatar
Member
Member
brandonm-salespad - 4/20/2012 8:26:25 AM
   
jQuery AJAX can't find code behind function.
The issue that I'm having is that when I make an jQuery AJAX call to a code behind function, it simply returns the HTML from the aspx page. It doesn't matter what I put after the slash (function name), it just returns the HTML form the page.

Here's my jQuery function.


function ajaxYo() {
jQuery.ajax({
type: "POST",
url: "SalesMonitor.aspx/GetCurrentTime",
data: '{name: "Brandon" }',
dataType: "json",
success: function (response) { alert("success!"); },
failure: function (response) { alert("failure!"); }
});


It will POST successfully, but the response is just HTML from the page and I don't get an actual alert, I'm just seeing the post and response in Firebug.

My .cs code behind function:

[System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
return "Yes";
}

User avatar
Member
Member
kentico_michal - 4/22/2012 8:56:34 AM
   
RE:jQuery AJAX can't find code behind function.
Hi,

Could you please specify the contentType as it is demontrated here:

function ajaxYo() {
jQuery.ajax({
type: "POST",
url: "SalesMonitor.aspx/GetCurrentTime",
data: '{name: "Brandon" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) { alert("success!"); },
failure: function (response) { alert("failure!"); }
});


Best regards,
Michal Legen


User avatar
Member
Member
brandonm-salespad - 4/23/2012 7:13:31 AM
   
RE:jQuery AJAX can't find code behind function.
That seems to have solved my issue! Thanks so much for the support. Sort of a bitter-sweet moment realizing there was just one little line of code missing.