asp.net dynamic list box "error fetching data"
Thank you for everyone's help so far! Have had some really helpful answers on this site so far. So I am hoping for one more.
What I want to create is exactly this, but i'm still having problems.
http://www.webonweboff.com/widgets/ajax/ajax_linked_selection.aspx
I have copied the html and javascript word for word and saved that file as index.html (but obviously with open and close html and body tags)
The file I have called ajaxServer.aspx.cs has the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
public partial class _Default : System.Web.UI.Page开发者_运维知识库
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/javascript";
string id = Request.QueryString.Get("id");
string action = Request.QueryString.Get("action");
StringBuilder returnString = new StringBuilder();
/*
Retrieve the data based on values "id" and "action"
and build a response string in this format:
[{text:"...",
*
* value:"...",selected:false},
{text...}]
No final ";" is necessary
For example:
returnString.Append("[{text:\"California\",value:\"CA\",selected:false}," +
"{text:\"OH\",value:\"Ohio\",selected:false}," +
"{text:\"NY\",value:\"New York\",selected:true}]");
*/
Response.Write(returnString.ToString());
}
}
and the file I have called ajaxServer.aspx has the following code:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="ajaxServer.aspx.cs" Inherits="_Default" %>
The other (.js) files I have downloaded and saved. When I run the .html file i get the following error:
error fetching data!
url:ajaxServer.asp
method:GET
params:action=state,culture=en-us
readyState:4
status:403
headers:Server: ASP.NET Development Server/10.0.0.0 Date: Sun, 19 Jun 2011 20:39:55 GMT X-AspNet-Version: 4.0.30319 Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 2126 Connection: Close
--> Any clues anyone? And once again - thank you for all the help in advance!
I'm guessing that this is a typo in their example code. ajaxServer.asp is refering to a classic asp page and not the ASPX page that you were asked to create. You're essentially telling the page to GET from a non-existent page.
Try changing the following line in the Javascript:
From this
var stateCities = new ylib.widget.AjaxLinkedSelection(
"state", "city",
"ajaxServer.asp",
"GET", paramsCity);
To this
var stateCities = new ylib.widget.AjaxLinkedSelection(
"state", "city",
"ajaxServer.aspx",
"GET", paramsCity);
Look at the source of the page and you'll see that the actual Javascript is refering to the aspx page. A check in Fiddler confirms that the aspx page is being requested and not the asp page.
精彩评论