jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Uncaught TypeError: Cannot set property 'dataAdapter' of undefined
This topic contains 1 reply, has 2 voices, and was last updated by Peter Stoev 10 years, 10 months ago.
-
Author
-
Hello,
I tried implementing JqxGrid with Web Service. This code is the same as provided in the link http://www.jqwidgets.com/jquery-widgets-documentation/documentation/asp.net-integration/asp.net-web-service-grid.htm
These are the errors i am receivingUncaught ReferenceError: jQuery is not defined localhost:1216/Scripts/jqx-all.js:7
Uncaught TypeError: Cannot set property ‘dataAdapter’ of undefined localhost:1216/Scripts/jqxdata.js:7
Uncaught TypeError: Cannot read property ‘dataAdapter’ of undefined localhost:1216/Default.aspx:This is my front end code
<head>
<script src=”Scripts/jqx-all.js” type=”text/javascript”></script>
<script src=”Scripts/jquery-2.1.1.min.js” type=”text/javascript”></script>
<link href=”Scripts/jqx.base.css” rel=”stylesheet” type=”text/css” />
<script src=”Scripts/jqxdata.js” type=”text/javascript”></script>
</head>
<script type=”text/javascript”>
// alert(“0”);
$(document).ready(function () {
// alert(“1”);
var source1 = {
type: “GET”,
datatype: “json”,
datafields: [
{ name: ‘firstname’, type: ‘string’ },
{ name: ‘lastname’, type: ‘string’ },
{ name: ‘productname’, type: ‘string’ },
{ name: ‘quantity’, type: ‘int’ },
{ name: ‘price’, type: ‘float’ },
{ name: ‘total’, type: ‘float’ }
],
url: ‘http://localhost:1216/Service.asmx/GetData’,
cache: false,
root: ‘data’
};
// alert(“2”);// alert(source.root);
//Preparing the data for usevar dataAdapter = new $.jqx.dataAdapter(source1, { contentType: ‘application/json; charset=utf-8’,
downloadComplete: function (data, textStatus, jqXHR) {alert(“3”);
return data.d;
}
}
);
$(“#jqxgrid”).jqxGrid({
source: dataAdapter,
columns: [
{ text: ‘First Name’, dataField: ‘firstname’, width: 100 },
{ text: ‘Last Name’, dataField: ‘lastname’, width: 100 },
{ text: ‘Product’, dataField: ‘productname’, width: 180 },
{ text: ‘Quantity’, dataField: ‘quantity’, width: 80, cellsalign: ‘right’ },
{ text: ‘Unit Price’, dataField: ‘price’, width: 90, cellsalign: ‘right’, cellsformat: ‘c2’ },
{ text: ‘Total’, dataField: ‘total’, cellsalign: ‘right’, minwidth: 100, cellsformat: ‘c2’ }
]
});
});
</script>
<div id=”jqxgrid”>
</div>Web Service code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net;
using System.IO;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Web.Script;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Text;
using System.Xml;namespace WebApplication1
{
/// <summary>
/// Summary description for Service
/// </summary>
[WebService(Namespace = “http://tempuri.org/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{/// <summary>
/// Service which is getting JSON string from the jQWidgets website
/// </summary>
/// <returns>JSON string</returns>
[WebMethod]
//[Serializable]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public object GetData()
{
string result;
WebResponse response;
WebRequest request = HttpWebRequest.Create(“http://www.jqwidgets.com/jquery-widgets-demo/demos/sampledata/data.php”);
response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
result = reader.ReadToEnd();
reader.Close();
}
return result;
//new JavaScriptSerializer().DeserializeObject(result);}
}
}Hi sdb,
jqx-all.js should be referenced after the jQuery Framework. In addition, jqxdata.js should not be referenced due to the fact that you load jqx-all.js which includes jqxdata.js. I also suppose that you will want IE8 compatibility in your app which means that jquery-2.1.1. is not the best choice for you. You should better use jQuery 1.x versions.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.