In the previous article <<EXTJS+WCF+LINQ implementation of paging grid>> with ExtJs and WCF Interactive implementation of the paging grid, reply center There are students hope to be able to use cross-domain access, this problem has also bothered me for a long time, It would have been extjs to support cross-domain access with Scripttagproxy, and if the server was an. aspx paging file, it would be very good to implement, but for WCF, the problem would be complicated. This article tries to solve this problem, the scheme is not very ingenious, but I am the first and only effective method in the experiment of many kinds of programs.
First look at how to use the Scripttagproxy across domains in ExtJS to access the server. aspx page, not the focus, but with why this method does not apply to WCF-related, so also to repeat, the project is the project above, the following is the implementation step:
The first step is to add the Service.aspx page to your Web site, and then change its code as follows:
Service.aspx Code
Using System;
Using System.Collections;
Using System.Configuration;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq;
Namespace Extjs_wcf_linq_pagegrid
{
public partial class Service:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
int start = Convert.ToInt32 (request.querystring["start");
int limit = Convert.ToInt32 (request.querystring["limit"]);
String callback = request.querystring["Callback"];
Productsdatacontext productdbcontext = new Productsdatacontext ();
iqueryable<product> res = productDbContext.Product.Select (product => product);
pagedata<product[]> returndata = new pagedata<product[]> ();
Returndata.totolrecord = Res. Toarray<product> (). Length;
res = Res. Skip<product> (start);
res = Res. Take<product> (limit);
Returndata.data = Res. Toarray<product> ();
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer (typeof (Pagedata<product[]>));
using (System.IO.MemoryStream ms = new System.IO.MemoryStream ())
{
Serializer. WriteObject (MS, Returndata);
Ms. Position = 0;
System.IO.StreamReader sr = new System.IO.StreamReader (MS);
Response.Write ("callback+" ("+SR"). ReadToEnd () + ")");
}
}
}
}
Step two: Create an HTM page pagegridcrossdomain.htm, and then change its code to:
Pagegridcrossdomain.htm
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>extjs+wcf+linq to create pagination grid</title>
<link rel= "stylesheet" type= "Text/css" href= "Resources/css/ext-all.css"/>
<script type= "Text/javascript" src= "Adapter/ext/ext-base.js" charset= "gb2312" ></script>
<script type= "Text/javascript" src= "Ext-all-debug.js" charset= "gb2312" ></script>
<link rel= "stylesheet" type= "Text/css" href= "Shared/examples.css"/>
<script type= "Text/javascript" src= "Shared/examples.js" charset= "gb2312" ></script>
<script src= "Scripttagreader.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" src= "Pagecrossdomain.js" charset= "gb2312" ></script>
<body>
Extjs+wcf+linq to create a paging cross-domain grid<div id= "Page-grid" >
</div>
</body>