Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling .Net webservice with Jquery is causing woe when trying to post data
    primarykey
    data
    text
    <p>The following code executes properly when the data key has no data to send, i.e. data: "{}" an empty JSON object and the webservice takes no parameters. I would like to post some data to the webservice but I am running into trouble.</p> <p>When I try to set this to data:"{'name':'Niall','surname':'Smith'}", I get an error</p> <pre><code>{"Message":"Invalid web service call, missing value for parameter: \u0027json\u0027.","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"} </code></pre> <p>The webservice is not executed.</p> <p>This is my Jquery call to post my data back to the server.</p> <pre><code> $.ajax({ type: "POST", url: "/WebServices/BasketServices.asmx/AddItemToBasket", data: "{'name':'niall'}", // Is this Correct?? contentType: "application/json; charset=utf-8", dataType: "json", success: OnItemAddedSuccess }); function OnItemAddedSuccess(result,eventArgs) { //deserialize the JSON and use it to update the Mini Basket var response = JSON.parse(result.d); } </code></pre> <p>here is my WebService</p> <pre><code>[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] [System.Web.Script.Services.ScriptService] public class BasketServices : System.Web.Services.WebService { [WebMethod(true)] public string AddItemToBasket(string json) { //do stuff return myString.toJSON(); } } </code></pre> <p>What could the problem be? Is it the format of the JSON data to be posted? Could it be that I haven't set the correct Attributes on my WebService. What about the problems alluded to in <a href="http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/" rel="noreferrer">Dave Ward's post</a></p> <p>I have tried everything I can think of. Does anyone have any ideas?</p>
    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.
 

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