【发布时间】:2011-03-14 14:03:38
【问题描述】:
我正在尝试从本地托管在 Xampp 上的 PHP、MySQL 服务将数据检索到我的 SL 应用程序。 我可以看到我的 php 文件运行正常并通过 JSON (http://localhost/silverlight/data.php) 提供结果,但 SL 无法接收它。我相信它与正确的 URl 路径有关,但我无法弄清楚。另外我把clientaccesspolicy.xml文件放到允许跨域访问但没有用:(
public partial class MainPage : UserControl
{
WebClient wc = new WebClient();
ObservableCollection<ToDoItem> myToDoList = new ObservableCollection<ToDoItem>();
string baseURI = "http://localhost/silverlight/";
public MainPage()
{
InitializeComponent();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri(baseURI + "data.php",UriKind.Absolute));
}
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null && e.Result!= "")
{ JsonValue completeResult = JsonPrimitive.Parse(e.Result);
string resultType = completeResult["returnType"].ToString().Replace("'", "").Trim();}
【问题讨论】:
-
能否请您发布您的
clientaccesspolicy.xml文件并仔细检查它是否位于http://localhost/clientaccesspolicy.xml -
取自MSDN的clientpolicy.xml为:[code]
[/code]
标签: php mysql silverlight json silverlight-4.0