PDA

View Full Version : [CLOSED] Status Code: Status Text: BADRESPONSE: Unexpected token <



hdsoso
Jun 10, 2014, 12:53 PM
http://forums.ext.net/attachment.php?attachmentid=12501&stc=1
aspx:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="art_list.aspx.cs" Inherits="web.qizweb.com.admin.pages.art_list" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
var renderUser = function (v) {
if (v != "") {
var index = App.store1.findExact("uid", v);
var r = App.store1.getAt(index);
return r.data.QizUser.uname;
} else {
return "";
}
};
var renderColumn = function (v) {
if (v != "") {
var index = App.store1.findExact("colid", v);
var r = App.store1.getAt(index);
return r.data.QizColumn.colname;
} else {
return "";
}
};
var renderArt = function (v, m, record) {
return "<a target='_blank' href='../../article.aspx?aid=" + record.data.id + "'>" + v + "</a>";
};
var nodeLoad = function (store, operation, options) {
var node = operation.node;

App.direct.NodeLoad(node.getId(), {
success: function (result) {
node.set('loading', false);
node.set('loaded', true);
var data = Ext.decode(result);
node.appendChild(data, undefined, true);
node.expand();
},

failure: function (errorMsg) {
Ext.Msg.alert('Failure', errorMsg);
}
});

return false;
};
var operArt = function (item, command, record, recordIndex, cellIndex) {
if (command == "Delete") {
Ext.MessageBox.confirm('提示', '确实要删除吗?', function (btn) {
if (btn == "yes") {
App.direct.OperArticle(command, record.data.id);
}
});
} else {
App.direct.OperArticle(command, record.data.id);
}

};
Ext.form.field.HtmlEditor.override({
append: function (v) {
this.setValue([this.getValue(), v].join(''));
}
});

</script>

</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" SourceFormatting="True"></ext:ResourceManager>
<ext:Window runat="server" Layout="FitLayout" Maximized="True" AutoScroll="True" Title="新增文章" ID="w_add" Hidden="True">

<Items>
<ext:FormPanel ID="fp_w" runat="server" Layout="AnchorLayout" AnchorVertical="100%" Margin="4" AnchorHorizontal="100%">
<Defaults>
<ext:Parameter Name="LabelWidth" Value="65" Mode="Raw" />
<ext:Parameter Name="Margin" Value="4" Mode="Raw" />
</Defaults>
<Items>
<ext:Hidden runat="server" ID="h_aid"></ext:Hidden>
<ext:DropDownField Margin="4" AnchorHorizontal="100%" MatchFieldWidth="False" LabelWidth="65" runat="server" ID="ddf_pid" Editable="false" FieldLabel="栏目" Mode="ValueText">
<Component>
<ext:TreePanel ID="TreePanel1" runat="server">
<Root>
<ext:Node NodeID="0" Text="根节点">
<CustomAttributes>
<ext:ConfigItem Name="id" Value="0" />
<ext:ConfigItem Name="colname" Value="根栏目" />
</CustomAttributes>
</ext:Node>
</Root>
<Listeners>
<BeforeLoad Fn="nodeLoad" />
</Listeners>
<Store>
<ext:TreeStore runat="server" ID="TreeStore1">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="id"></ext:ModelField>
<ext:ModelField Name="colname"></ext:ModelField>
<ext:ModelField Name="pid"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:TreeStore>
</Store>
<ColumnModel>
<Columns>
<ext:TreeColumn ID="TreeColumn1" runat="server" DataIndex="colname" Text="栏目" Flex="1" Width="300">
</ext:TreeColumn>
</Columns>
</ColumnModel>
<Listeners>
<ItemClick Handler="#{ddf_pid}.setValue(record.data.id,record.data.col name);"></ItemClick>
<AfterRender Handler="#{TreePanel1}.expandAll();"></AfterRender>
</Listeners>
</ext:TreePanel>
</Component>
</ext:DropDownField>
<ext:TextField runat="server" ID="tf_title" FieldLabel="标题" LabelWidth="65" AnchorHorizontal="100%" Margin="4"></ext:TextField>
<ext:FileUploadField runat="server" FieldLabel="缩略图" ID="fuf_slt" ButtonText="上传..." AnchorHorizontal="25%"></ext:FileUploadField>
<ext:FieldContainer runat="server" Hidden="True" ID="fc_yl" FieldLabel="图片预览" AnchorHorizontal="100%">
<Items>
<ext:Image runat="server" ID="i_img" Hidden="true" Height="90" Width="200"></ext:Image>
</Items>

</ext:FieldContainer>

<ext:TextArea runat="server" FieldLabel="简介" ID="ta_jj" AnchorHorizontal="100%"></ext:TextArea>
<ext:FieldContainer runat="server" LabelWidth="65" Margin="4" FieldLabel="工具" Layout="HBoxLayout">
<Items>
<ext:MultiUpload runat="server" ID="mu_1" OnFileUpload="MultiUpload1_FileUpload"
AutoStartUpload="true"
FileDropAnywhere="true"
FileSizeLimit="15 MB"
FileTypes="*.jpg;*.png;*.doc;*.zip"
FileTypesDescription="All Files"
FileUploadLimit="100"
FileQueueLimit="0">
<Button>
<ext:Button runat="server" Text="上传图片"></ext:Button>
</Button>
<Listeners>
<UploadStart Handler="Ext.Msg.wait('上传中');" />
<UploadComplete Handler="Ext.Msg.hide();" />
</Listeners>
</ext:MultiUpload>
<ext:Button runat="server" Icon="DiskDownload" Text="图片本地化" ID="Button2">
<DirectEvents>
<Click OnEvent="SavePics">
<EventMask ShowMask="True"></EventMask>
</Click>
</DirectEvents>
</ext:Button>
<ext:Button runat="server" Icon="ControlRemove" Text="除广告">
<DirectEvents>
<Click OnEvent="RemoveAd">
<EventMask ShowMask="True"></EventMask>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:FieldContainer>


<ext:HtmlEditor runat="server" ID="he_cont" AnchorHorizontal="100%" AnchorVertical="-78">
</ext:HtmlEditor>
</Items>
<Buttons>
<ext:Button runat="server" Text="确定">
<DirectEvents>
<Click OnEvent="AddArticle"></Click>
</DirectEvents>
</ext:Button>
<ext:Button runat="server" Text="取消">
<Listeners>
<Click Handler="#{fp_w}.reset();"></Click>
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Items>
<Listeners>
<Close Handler="#{fp_w}.reset();App.i_img.imgUrl='';App.i_img.hide ();App.fc_yl.hide();"></Close>
</Listeners>
</ext:Window>
<ext:Viewport runat="server" Layout="FitLayout">
<Items>
<ext:GridPanel runat="server" Title="文章管理">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="新增" Icon="ApplicationFormAdd">
<DirectEvents>
<Click OnEvent="ShowAddWindow"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store runat="server" ID="store1" OnReadData="LoadArticles" PageSize="50">
<Model>
<ext:Model runat="server" IDProperty="id">
<Fields>
<ext:ModelField Name="id" Type="Int"></ext:ModelField>
<ext:ModelField Name="title" Type="String"></ext:ModelField>
<ext:ModelField Name="uid" Type="String"></ext:ModelField>
<ext:ModelField Name="QizUser" Type="Object">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id"></ext:ModelField>
<ext:ModelField Name="email"></ext:ModelField>
<ext:ModelField Name="uname"></ext:ModelField>
<ext:ModelField Name="upass"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:ModelField>
<ext:ModelField Name="colid" Type="String"></ext:ModelField>
<ext:ModelField Name="QizColumn" Type="Object">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id"></ext:ModelField>
<ext:ModelField Name="colname"></ext:ModelField>
<ext:ModelField Name="pid"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:ModelField>
<ext:ModelField Name="addtime" Type="Date"></ext:ModelField>
<ext:ModelField Name="cont"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
<Proxy>
<ext:PageProxy></ext:PageProxy>
</Proxy>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column runat="server" DataIndex="id" Text="编号">
</ext:Column>

<ext:Column runat="server" DataIndex="title" Text="标题" Flex="1">
<Renderer Fn="renderArt"></Renderer>
</ext:Column>
<ext:Column runat="server" DataIndex="colid" Text="栏目">
<Renderer Fn="renderColumn"></Renderer>

</ext:Column>
<ext:Column runat="server" DataIndex="uid" Text="作者">
<Renderer Fn="renderUser"></Renderer>
</ext:Column>
<ext:DateColumn runat="server" DataIndex="addtime" Text="发表时间" Format="yyyy-MM-dd"></ext:DateColumn>
<ext:CommandColumn runat="server" Text="操作">
<Commands>

<ext:GridCommand Icon="NoteEdit" CommandName="Edit">
<ToolTip Text="修改"></ToolTip>
</ext:GridCommand>
<ext:GridCommand Icon="Delete" CommandName="Delete">
<ToolTip Text="删除"></ToolTip>
</ext:GridCommand>
</Commands>
<Listeners>
<Command Fn="operArt" />
</Listeners>
</ext:CommandColumn>
</Columns>
</ColumnModel>

<BottomBar>
<ext:PagingToolbar runat="server" StoreID="store1"></ext:PagingToolbar>
</BottomBar>
<Plugins>
<ext:FilterHeader ID="FilterHeader1" runat="server" Remote="true" />
</Plugins>
<SelectionModel>
<ext:RowSelectionModel runat="server" Mode="Multi" ID="CellSelectionModel1"></ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>
</Items>
</ext:Viewport>

</form>
</body>
</html>



cs


using System;
using System.Net;
using System.Text.RegularExpressions;
using System.Web;
using Ext.Net;
using model.qizweb.com;
using service.qizweb.com;
using tools.qizweb.com;
using webbase.qizweb.com;

namespace web.qizweb.com.admin.pages
{
public partial class art_list : BasePageAdmin
{
ArtService artService = new ArtService();
ColumnService _columnService = new ColumnService();
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
}
}
[DirectMethod]
public string NodeLoad(string nodeID)
{
NodeCollection nodes = new Ext.Net.NodeCollection();
var ll = _columnService.GetChildColumn(int.Parse(nodeID));
foreach (var column1 in ll)
{
Node n = new Node();
n.Text = column1.colname;
n.CustomAttributes.Add(new ConfigItem("id", column1.id.ToString()));
n.CustomAttributes.Add(new ConfigItem("colname", column1.colname));
n.CustomAttributes.Add(new ConfigItem("pid", nodeID));
n.NodeID = column1.id.ToString();
var _ll = _columnService.GetChildColumn(column1.id);
if (_ll.Count <= 0) n.Leaf = true;
else n.Expanded = true;
nodes.Add(n);
}
return nodes.ToJson();
}
protected void LoadArticles(object sender, StoreReadDataEventArgs e)
{
var fhc = new FilterHeaderConditions(e.Parameters["filterheader"]);
string dataIndex = string.Empty;
object value = null;
foreach (FilterHeaderCondition condition in fhc.Conditions)
{
dataIndex = condition.DataIndex;
FilterType type = condition.Type;
string op = condition.Operator;
value = null;

switch (condition.Type)
{
case FilterType.Boolean:
value = condition.Value<bool>();
break;

case FilterType.Date:
value = condition.Value<DateTime>();
break;

case FilterType.Numeric:
value = condition.Value<int>();
break;

case FilterType.String:
value = condition.Value<string>();
break;
default:
throw new ArgumentOutOfRangeException();
}

}

int start = e.Start;
int limt = e.Limit;
var total = 0;
var ll = artService.PageArts(start, limt, out total, dataIndex, value);
e.Total = total;
store1.DataSource = ll;
store1.DataBind();
}
protected void ShowAddWindow(object sender, DirectEventArgs e)
{
w_add.SetTitle("新增文章");
w_add.Hidden = false;
}
protected void AddArticle(object sender, DirectEventArgs e)
{

var title = tf_title.Text;
var cont = he_cont.Text;
int colid = int.Parse(ddf_pid.Value.ToString());
var img = string.Empty;
var thumb = string.Empty;
if (fuf_slt.HasFile)
{
HttpPostedFile f = fuf_slt.PostedFile;
var uploadedFile = new UploadedFile(f.FileName, "yyyy-MM-dd-HH-mm-ss");
f.SaveAs(uploadedFile.PhysicalFilePath);
img = uploadedFile.WebPath;
GenerateThumbnail.GenThumbnail(uploadedFile.Physic alFilePath, uploadedFile.ThumbFile, 300, 200);
thumb = uploadedFile.WebthumbFile;
}
var jj = ta_jj.Text;
var u = ( QizUser)Session["user"];
if (u == null)
{
Response.Write("<script>parent.window.location='/admin/pages/login.aspx'</script>");
Response.End();
}
var uid = u.id;
var now = DateTime.Now;

if (h_aid.Value.ToString() != "")
{

var id = int.Parse(h_aid.Value.ToString());
var qizart = artService.Get(id);
qizart.title = title;
qizart.cont = cont;
qizart.shortdesc = jj;
if (fuf_slt.HasFile)
{
qizart.pic = img;
qizart.thumbs = thumb;
}
qizart.addtime = now;
qizart.uid = uid;
qizart.colid = colid;
try
{
artService.Update(qizart);
}
catch (Exception)
{
SysTools.Alert("更新文章出错");
}
}
else
{
var a = new QizArticle { title = title, cont = cont, uid = uid, colid = colid, addtime = now, pic = img, shortdesc = jj, thumbs = thumb };
try
{
artService.Add(a);
}
catch (Exception)
{
SysTools.Alert("新增文章出错");
}
}

w_add.Hidden = true;
fp_w.Reset();
store1.Reload();
}
protected void MultiUpload1_FileUpload(object sender, FileUploadEventArgs e)
{
HttpPostedFile f = e.PostedFile;
var fname = f.FileName;
var uploadedFile = new UploadedFile(fname, "yyyy-MM-dd-HH-mm-ss");
f.SaveAs(uploadedFile.PhysicalFilePath);
var img = string.Empty;
if ((".jpg").Equals(uploadedFile.HouZhui) || ".png".Equals(uploadedFile.HouZhui))
{
img = string.Format("<a href={0} target='_blank'><img src='{1}'/></a></br>", uploadedFile.WebPath, uploadedFile.WebPath);
}
else if (".zip".Equals(uploadedFile.HouZhui))
{
img = string.Format("<a href={0} target='_blank'><img src='{1}'/></a></br>", uploadedFile.WebPath, "../../admin/images/zip.png");
}
else if (".doc".Equals(uploadedFile.HouZhui))
{
img = string.Format("<a href={0} target='_blank'><img src='{1}'/></a></br>", uploadedFile.WebPath, "../../admin/images/doc.png");
}
he_cont.Call("append", img);
}
protected void RemoveAd(object sender, DirectEventArgs e)
{
var editorContent = he_cont.Text;
var content = Regex.Replace(editorContent, @"<div[^>]+><iframe[^>]+></iframe></div>", string.Empty, RegexOptions.IgnoreCase);
he_cont.Text = content;
}
protected void SavePics(object sender, DirectEventArgs e)
{
var editorContent = he_cont.Text;

// Regex reg = new Regex(@"(?is)<img[^>]*?src=(['""\s]?)((?:(?!topics)[^'""\s])*)\1[^>]*?>");
Regex reg = new Regex("<img.+?src=[\"'](.+?)[\"'].+?>");
foreach (Match m in reg.Matches(editorContent))
{
var url = m.Groups[1].Value;
var uploadedFile = new UploadedFile(url, "yyyy-MM-dd-HH-mm-ss");
var mywebclient = new WebClient();
try
{
mywebclient.DownloadFile(url, uploadedFile.PhysicalFilePath);
}
catch (Exception ex)
{
X.Msg.Alert("消息", "下载失败");
}
var wp = uploadedFile.WebPath;
editorContent = editorContent.Replace(url, wp);// here replace the original src with new one?

}
he_cont.Text = editorContent;
}

[DirectMethod]
public void OperArticle(string command, int id)
{
if ("Delete".Equals(command))
{
try
{
artService.Delete(id);
}
catch (Exception)
{
X.Msg.Alert("消息", "删除失败").Show();
}
store1.Reload();

}
else if ("Edit".Equals(command))
{
i_img.ImageUrl = "";
fp_w.Reset();

QizArticle a = artService.Get(id);
h_aid.Value = a.id;
ddf_pid.SetValue(a.QizColumn.id.ToString(), a.QizColumn.colname);
tf_title.Text = a.title;
he_cont.Text = a.cont;
fc_yl.Show();
i_img.Show();
i_img.ImageUrl = string.IsNullOrEmpty(a.pic) ? "../../images/case_title.gif" : a.pic;
ta_jj.Text = a.shortdesc;
w_add.Title = "修改文章";
w_add.Show();
}

}

}
}

if i remove write a sample code ,no error.
first click "新增" then click "上传图片" , will face the error

hdsoso
Jun 10, 2014, 1:18 PM
when i remove the newtownsoft.json and add it again.
12511
my ext.net version is 2.5.1.24957
runable version is v4.0.30319
i think newtownsoft.json not compatible with ext.net?

hdsoso
Jun 10, 2014, 1:20 PM
the codes above work fine when ext.net 2.4

Daniil
Jun 10, 2014, 3:05 PM
Hi @hdsoso,

Unfortunately, I cannot run the code to investigate the issue in details.

Please post a response of a "Bad Response" request. Maybe, it could clarify something. Though, providing us with a runnable test case is better.



i think newtownsoft.json not compatible with ext.net?

Not sure I understand the question. Ext.NET uses Newtonsoft.Json.dll.

hdsoso
Jun 10, 2014, 3:52 PM
how can i provide you more detail ?unfortunately, take a full test case need more time , in my case , when I click the button "上传图片", then show the error, the code run fine in ext.net 2.4 .
12521

hdsoso
Jun 10, 2014, 4:18 PM
i know why now, when i click "上传图片" button, then execute basepage,BasePageAdmin


<ext:MultiUpload runat="server" ID="mu_1" OnFileUpload="MultiUpload1_FileUpload"
AutoStartUpload="true"
FileDropAnywhere="true"
FileSizeLimit="15 MB"
FileTypes="*.jpg;*.png;*.doc;*.zip"
FileTypesDescription="All Files"
FileUploadLimit="100"
FileQueueLimit="0">
<Button>
<ext:Button runat="server" Text="上传图片"></ext:Button>
</Button>
<Listeners>
<UploadStart Handler="Ext.Msg.wait('上传中');" />
<UploadComplete Handler="Ext.Msg.hide();" />
</Listeners>
</ext:MultiUpload>



public partial class ArtList : BasePageAdmin
{
readonly ArtService _artService = new ArtService();
readonly ColumnService _columnService = new ColumnService();
protected void Page_Load(object sender, EventArgs e)
{

}

BasePageAdmin


public class BasePageAdmin : System.Web.UI.Page
{

protected override void OnLoad(EventArgs e)
{
if (!IsPostBack)
{
var url = Request.RawUrl;
if (url.Contains("admin") && url != "/admin/pages/login.aspx")
{
if (Session["user"] == null)//
{
Response.Write("<script>parent.window.location='/admin/pages/login.aspx'</script>");
Response.End();
}

the Session["user"] ==null result the error above, but when i click other control , the session is not null , may be a bug in MultiUpload ?

Daniil
Jun 10, 2014, 7:02 PM
Have you the code in Global.asax, suggested here?
http://examples2.ext.net/#/MultiUpload/Basic/Overview/