Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON stringify to C# Webservice
    primarykey
    data
    text
    <p>I know there are a few questions out there but I've tried a lot of them and I'm still not able to even get my script to make it to the server. Here is what I currently have:</p> <p><strong>Javascript</strong></p> <pre><code>function UpdateSessionUser(user) { if (user != null) { var targetPage = "http://" + document.location.host + "/Sitefinity/Services/Sandbox/SessionUsers.asmx/UpdateSessionUser"; var dataText = { "jsonUser" : JSON.stringify(user) }; try { $.ajax({ type: "POST", url: targetPage, data: dataText, contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { alert(response.d); return true; }, failure: function (msg) { alert(msg); return false; } }); } catch (err) { alert(err); } } } </code></pre> <p><strong>Example of user object</strong></p> <pre><code>Object BaseID: "fe85149c-71f2-4c61-b7c6-a00300e2f84e" HasChanged: true IsReferralReceived: false IsReferralRequired: true IsSeatApproved: true Name: "Miles" ReferralFromUser: null ReferralFromUserID: null ReferralReceivedBy: null ReferralReceivedByUserID: null ReferralReceivedOn: "/Date(-62135578800000)/" RegisteredOn: "1330281960000" SeatApprovedBy: null SeatApprovedByUserID: null SeatApprovedOn: "/Date(-62135578800000)/" SeatNumber: "2" SessionID: "d0773d5e-aeeb-4b9c-b606-0a564d6c5845" UserID: "6af2fd9e-b4b6-4f5a-8e9c-fe7ec154d4e5" __type: "SandboxClassRegistration.SessionUserField.ClientSessionUser" </code></pre> <p><strong>C#</strong></p> <pre><code>[WebMethod] public bool UpdateSessionUser(object jsonUser) { return SessionUserHelper.UpdateSessionUser(new ClientSessionUser(jsonUser)); } </code></pre> <p>Why does my JSON call never make it to the server? I've put a break point at the very beginning of the function (before the return) just so I can look at the jsonUser object parameter but it never makes it there.</p> <p>All I get in return is this error:</p> <p><em><strong>POST <a href="http://localhost:60877/Sitefinity/Services/Sandbox/SessionUsers.asmx/UpdateSessionUser" rel="nofollow">http://localhost:60877/Sitefinity/Services/Sandbox/SessionUsers.asmx/UpdateSessionUser</a> 500 (Internal Server Error)</em></strong></p> <p>--- UPDATE</p> <p>Here is the final result (I had to "stringify" the object and then the final dataText being sent). The webservice method was unchanged</p> <pre><code>function CallWebServiceToUpdateSessionUser(target, user) { var dataText = { "jsonUser": JSON.stringify(user) }; $.ajax({ type: "POST", url: target, data: JSON.stringify(dataText), contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { alert(response.d); return true; }, failure: function (msg) { alert(msg); return false; } }); } </code></pre>
    singulars
    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.
 

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