jQuery ajax returns entire page content instead of result

Jore

New Member
I have to add functionality to a VS 2008 (.Net 3.5) web site that is using Synapse's content management system. After struggling for many hours I started from scratch and the following works in a brand new web project.Here is the client-side script and html:\[code\]<script type="text/javascript">function ClickedIt() { $.ajax({ type: "POST", url: "Default.aspx/FromClient", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { alert(msg.d); } });} // ClickedItfunction ClickedItDeeper() { $.ajax({ type: "POST", url: "/Deeper/ActionsController.aspx/FromClient", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { alert(msg.d); } });} // ClickedItDeeper</script><asp:Button ID="btnClickMe" runat="server" Text="Click Me - Server" />&nbsp;&nbsp;<asp:Button ID="btnViaClient" runat="server" Text="Click Me - Client" OnClientClick="ClickedIt(); return false;" />&nbsp;&nbsp;<asp:Button ID="btnDeeper" runat="server" Text="Click Me - Deeper" OnClientClick="ClickedItDeeper(); return false;" />\[/code\]Even better yet, I have to write it in VB, so here are the two different tests I am calling. One is the actual page I am running (Default.aspx) and the other is the way I like to do it to keep the methods together (ActionsController.aspx):\[code\]Imports System.Web.Services Partial Public Class _Default Inherits System.Web.UI.PageProtected Sub btnClickMe_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClickMe.Click Me.lblResult.Text = "From the Server Side: " + DateTime.Now.ToString()End Sub<WebMethod()> _Public Shared Function FromClient() As String Return "Via the Client: " + DateTime.Now.ToString()End FunctionEnd Class\[/code\]The ActionsController is:\[code\]Imports System.Web.ServicesPartial Public Class ActionsControllerInherits System.Web.UI.Page<WebMethod()> _Public Shared Function FromClient() As String Return "Via the Deeper Client: " + DateTime.Now.ToString()End FunctionEnd Class\[/code\]All of the above works like a champ in that isolated site. However, when I try to do the same thing in this CMS site, I get a: parseerror: invalid character. After looking at many MANY articles out there (none fixed it) one had mentioned that perhaps the telerik or even the CMS software was overwriting JSON.parse and it seems as if it was. I forced it to not use the other and now it is using json2.js. When I put an:\[code\]alert(text);\[/code\]just inside the json2.js file:\[code\]JSON.parse = function(text, reviver) {\[/code\]it shows me the entire html page content, which is the page not found when I call it with this:\[code\]$.ajax({type: "POST",url: "ActionsController.aspx/FromClient",data: "{}",contentType: "application/json",dataType: "json",success: function(msg) { $("#lblResult").html(msg); alert("success");},error: function(xhr, textStatus, errorThrown) { alert("Ajax error on " + this.url + "\nStatus: " + textStatus + "\nError: " + errorThrown + "\nText: " + xhr.statusText + "\nxhrStatus: " + xhr.status );}});\[/code\]Gives me a error of SyntaxError: JSON.parse but a text value of OK and status of 200.I have changed the URL to not have the leading / and added en-US to the start with and without the leading slash all to no avail. I am not sure if the page not found is legit. Initially the ActionsController page was in a folder. I have since moved it to the root of the site.This is something I have done so many times on VS2010. It works in VS2008 but I figure something is getting in the way and either attaching something to the URL or something thanks to this CMS. When it errors, I do have it passing me the this.url which is: /ActionsController.aspx/FromClient so that works for me.Here is the actual ActionsController code for broken site:\[code\]Imports System.Web.ServicesPartial Public Class ActionsControllerInherits System.Web.UI.Page<WebMethod()> _ Public Shared Function FromClient() As String Return "Via the Deeper Client: " + DateTime.Now.ToString()End Function<WebMethod()> _Public Shared Function Multiply(ByVal Input As Integer) As String Return "Via the Deeper Client: " + DateTime.Now.ToString()End FunctionEnd Class\[/code\]One more hour and it will be a full day of just searching and tweaking and testing on something that is probably so simple but hidden beneath layers and layers of "functionality" from telerik and synapse.Please make my day!
 
Back
Top