Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing JSON object from client to server
    primarykey
    data
    text
    <p>I am having trouble making a client site AJAX call and then passing the JSON object response to server side using PageMethods to do some conditional logic</p> <p>The JSON response received back from the web service is: </p> <pre><code>{"Status":"Internal"} </code></pre> <p>Default.aspx</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GoRedirect._Default" %&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"&gt; &lt;/asp:ScriptManager&gt; &lt;script type="text/javascript"&gt; function invokeService() { $(document).ready(function () { $.ajax({ type: "GET", async: "false", url: "http://Domain.Local/InternalCheck/", dataType: "json", success: function (result) { AjaxSucceeded(result); }, error: AjaxFailed }); }); } function AjaxSucceeded(result) { var objJSON = result.Status; PageMethods.GetJSONResponse(objJSON); } function AjaxFailed(result) { alert(result.status + ' ' + result.statusText); } invokeService(); &lt;/script&gt; &lt;/form&gt; </code></pre> <p> </p> <p>Default.aspx.cs</p> <pre><code>namespace GoRedirect { public partial class _Default : Page { [Serializable] public class ServerJSON { public string Status { get; set; } } [WebMethod] public static string GetJSONResponse(string objJson) { try { JavaScriptSerializer serializer = new JavaScriptSerializer(); string JSONResponse = serializer.Serialize(objJson); return JSONResponse; } catch(Exception errorException) { return errorException.ToString(); } } public void Page_Load(object sender, System.EventArgs e) { If (JSONResponse.Status == "Internal") { //Do something } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload