Well the reponseText property of the XHR object contains :

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/";>{"results": [
            {
                "id": "4",
                "value": "guardian.co.uk"
            }
        ]}</string>


that's what the webservice returns. Since dataType of my jquery ajax
method is set to 'json', this should be interpreted as json data.


On 30 jan, 11:14, Beres Botond <boton...@gmail.com> wrote:
> So the AJAX call actually returns some result now?
>
> If you alert() the result, before trying to do anything with it, what
> do you get?
>
> On Jan 30, 11:35 am, graphicsxp <graphic...@googlemail.com> wrote:
>
> > >This should only be set if your webservice expects the input parameter
> > >in JSON format as well, and not only the response is JSON.
> > >Is this the case?
>
> > Yes, I thought that too. I've removed the contentType parameter. In
> > this case the webservice is reached.
> > But when the AJAX call returns I get the error 'parseerror' .
>
> > The webservice method looks like :
>
> >  [WebMethod]
> >     public string GetPublication(String pText) {
> >       String result = "";
>
> >       result = @"{""results"": [
> >             {
> >                 ""id"": ""4"",
> >                 ""value"": ""guardian.co.uk""
> >             }
> >         ]}";
>
> >       return result;
> >     }
>
> > On 30 jan, 09:30, Beres Botond <boton...@gmail.com> wrote:
>
> > > A parameter has to be key=>value, in some form, otherwise how is it
> > > identified?
>
> > > contentType: "application/json; charset=utf-8",
>
> > > This should only be set if your webservice expects the input parameter
> > > in JSON format as well, and not only the response is JSON.
> > > Is this the case?
>
> > > How does the code of your webservice look like? (the part which gets
> > > the input parameter)
>
> > > On Jan 29, 6:50 pm, graphicsxp <graphic...@googlemail.com> wrote:
>
> > > > Thanks.. I tried that but I'm getting an error before the webservice
> > > > is reached :  "Invalid JSON primitive: pText."
>
> > > > Like I said, my webservice's method expects a string, not a JSON key-
> > > > value  pair. I'd be surprised if we can't pass a simple string to a
> > > > webservice ?
>
> > > > On 29 jan, 16:24, MorningZ <morni...@gmail.com> wrote:
>
> > > > > Right from the docshttp://docs.jquery.com/Ajax/jQuery.ajax#options
>
> > > > > "Object must be Key/Value pairs"
>
> > > > > something that
>
> > > > > data: "pText=some text"
>
> > > > > is not  (it's a string)
>
> > > > > so with that pointed out, try
>
> > > > > $.ajax({
> > > > >           url: "Publication.asmx/GetPublication",
> > > > >           data: { pText: "some text" },
> > > > >           type: "POST",
> > > > >           contentType: "application/json; charset=utf-8",
> > > > >           dataType: "json",
>
> > > > > });
>
> > > > > On Jan 29, 10:58 am, graphicsxp <graphic...@googlemail.com> wrote:
>
> > > > > > Hi,
>
> > > > > > I'm trying to send a string to my webservice. The method I call
> > > > > > expects a string parameter and returns a string of JSON data.
>
> > > > > > I've tried this way :
>
> > > > > >  $.ajax({
> > > > > >           url: "Publication.asmx/GetPublication",
> > > > > >           data: "pText=some text",
> > > > > >           type: "POST",
> > > > > >           contentType: "application/json; charset=utf-8",
> > > > > >           dataType: "json",
>
> > > > > > });
>
> > > > > > in which case I get the following error and the webservice is not 
> > > > > > even
> > > > > > reached :
>
> > > > > > Invalid JSON primitive: pText
>
> > > > > > and this way :
>
> > > > > >  $.ajax({
> > > > > >           url: "Publication.asmx/GetPublication",
> > > > > >           data: "pText=some text",
> > > > > >           type: "POST",
> > > > > >           dataType: "json",
>
> > > > > > });
>
> > > > > > in which case the webservice is reached but then when the ajax call
> > > > > > returns I get the following error :
>
> > > > > > parseerror
>
> > > > > > What do i need to do to fix this ?
>
> > > > > > Thanks

Reply via email to