Author Topic: Uncaught Error : SyntaxError: Unexpected token < in JSON at position 0  (Read 3059 times)

mms

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hi Every one,

I integrate the Paramquery grid in my asp.net application, with static data it is working fine. but in dynamic data i am getting an error that is: "Uncaught Error : SyntaxError: Unexpected token < in JSON at position 0".

Let me share code with you. can please someone help me to fixed that issue?
  obj.dataModel = {
            dataType: "JSON",
            location: "remote",
            method:"GET",
            url: "/WebSrvPoline.asmx/getData",
            getData: function (response) {
                return { data: response }; //data: response.data //(I tried both nothing work)
            }
}

getting data from asp.net function.

{"data":[{"POLINENUM":1,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"8\u0027\u0027 x 3\u0027\u0027 x 47mm - GI Box","ORDERQTY":650.0000,"ORDERUNIT":"Nos","UNITCOST":1.5700,"LINECOST":1020.5000},{"POLINENUM":1,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"8\u0027\u0027 x 3\u0027\u0027 x 47mm - GI Box","ORDERQTY":650.0000,"ORDERUNIT":"Nos","UNITCOST":1.5700,"LINECOST":1020.5000},{"POLINENUM":2,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm PVC Conduct x 1.9mm (2.92 mtr/length)","ORDERQTY":30000.0000,"ORDERUNIT":"Length","UNITCOST":2.5000,"LINECOST":75000.0000},{"POLINENUM":2,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm PVC Conduct x 1.9mm (2.92 mtr/length)","ORDERQTY":30000.0000,"ORDERUNIT":"Length","UNITCOST":2.5000,"LINECOST":75000.0000},{"POLINENUM":3,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm PVC Coupler","ORDERQTY":60000.0000,"ORDERUNIT":"Nos","UNITCOST":0.1700,"LINECOST":10200.0000},{"POLINENUM":3,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm PVC Coupler","ORDERQTY":60000.0000,"ORDERUNIT":"Nos","UNITCOST":0.1700,"LINECOST":10200.0000},{"POLINENUM":4,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm PVC Saddle","ORDERQTY":10000.0000,"ORDERUNIT":"Nos","UNITCOST":0.3200,"LINECOST":3200.0000},{"POLINENUM":4,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm PVC Saddle","ORDERQTY":10000.0000,"ORDERUNIT":"Nos","UNITCOST":0.3200,"LINECOST":3200.0000},{"POLINENUM":5,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"50mm PVC long Radius Bend","ORDERQTY":1200.0000,"ORDERUNIT":"Nos","UNITCOST":6.7400,"LINECOST":8088.0000},{"POLINENUM":5,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"50mm PVC long Radius Bend","ORDERQTY":1200.0000,"ORDERUNIT":"Nos","UNITCOST":6.7400,"LINECOST":8088.0000},{"POLINENUM":6,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm PVC Female Adaptor","ORDERQTY":42000.0000,"ORDERUNIT":"Nos","UNITCOST":0.2500,"LINECOST":10500.0000},{"POLINENUM":6,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm PVC Female Adaptor","ORDERQTY":42000.0000,"ORDERUNIT":"Nos","UNITCOST":0.2500,"LINECOST":10500.0000},{"POLINENUM":7,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"50mm PVC Female Adaptor","ORDERQTY":2000.0000,"ORDERUNIT":"Nos","UNITCOST":0.9100,"LINECOST":1820.0000},{"POLINENUM":7,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"50mm PVC Female Adaptor","ORDERQTY":2000.0000,"ORDERUNIT":"Nos","UNITCOST":2.0300,"LINECOST":4060.0000},{"POLINENUM":8,"LINETYPE":"ITEM","COSTCODE":"ME0100","CATALOGCODE":null,"ITEMDESCRIPTION":"50mm PVC Coupler","ORDERQTY":2000.0000,"ORDERUNIT":"Nos","UNITCOST":0.9100,"LINECOST":1820.0000},{"POLINENUM":8,"LINETYPE":"ITEM","COSTCODE":"ME0100","CATALOGCODE":null,"ITEMDESCRIPTION":"50mm PVC Coupler","ORDERQTY":2000.0000,"ORDERUNIT":"Nos","UNITCOST":0.9100,"LINECOST":1820.0000},{"POLINENUM":9,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm Flexible Corrugated Conduit - 50mtr/coll","ORDERQTY":50.0000,"ORDERUNIT":"Rolls","UNITCOST":40.6600,"LINECOST":2033.0000},{"POLINENUM":9,"LINETYPE":"ITEM","COSTCODE":"ME0010","CATALOGCODE":null,"ITEMDESCRIPTION":"25mm Flexible Corrugated Conduit - 50mtr/coll","ORDERQTY":50.0000,"ORDERUNIT":"Rolls","UNITCOST":40.6600,"LINECOST":2033.0000}]}

even if i remove data keywords, it still not be working. Can you please help me how can i fixed.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Error states the format of json is incorrect, you need to check that.

And it would be response.data in getData callback.

mms

  • Newbie
  • *
  • Posts: 2
    • View Profile

            var products2 = (from product in (List<POLINE>)Session["POLINE"]
                             orderby product.POLINENUM
                             select product);
This is my asp.net function.

            StringBuilder sb = new StringBuilder(@"{""data"":");

            JavaScriptSerializer js = new JavaScriptSerializer();

            string json = js.Serialize(products2);
            sb.Append(json);
            sb.Append("}");

            return   sb.ToString();

it giving an error on this : ("/WebSrvPoline.asmx/getData") (Uncaught Error : SyntaxError: Unexpected token < in JSON at position 0)
This portion is not begin executing.

 getData: function (response) {
                var data = response.data;
                return { data: data };
            }

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
There might be an error in your remote script.

Try to open url directly in browser.  http://........./WebSrvPoline.asmx/getData