AJAX回调的readyState 4,状态404的Windows Phone 8.1 [英] ajax call back readyState 4, status 404 in windows phone 8.1

查看:872
本文介绍了AJAX回调的readyState 4,状态404的Windows Phone 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IBM工作灯混合应用程序。

在我的Windows Phone 8.1,当我运行此应用程序,AJAX调用返回的readyState 4,状态404。

我是不是做错了什么?任何帮助将大大AP preciated。

项目文件的层次这里

AJAX请求code:

  $。阿贾克斯({
    键入:搞定,
    网址:的index.html,
    成功:功能(数据){警报(成功+ JSON.stringify(数据)); },
    错误:功能(错误){警报(错误+ JSON.stringify(错误));}
});
 

解决方案

您面前的页面名称追加WWW /默认的,因为在Windows Phone的MainPage.xaml中第一次加载,这是在根目录。和$就将会从搜索根目录,因此你必须给如下路径。

  $。阿贾克斯({
    键入:搞定,
    网址:WWW /默认/ index.html的,
    成功:功能(数据){警报(成功+ JSON.stringify(数据)); },
    错误:功能(错误){警报(错误+ JSON.stringify(错误));}
});
 

如果您的应用程序有太多的 $。阿贾克斯 $。获得,你不希望修改每一个要求,你可以使用以下全局AJAX设置,当你的应用程序启动。

  $。ajaxSetup({
    beforeSend:功能(jqXHR,设置){
        settings.url =WWW /默认/+ settings.url;
    }
});
 

I am making hybrid application using IBM Worklight.

In my windows phone 8.1, when I am running this application, ajax calls returns readyState 4, status 404.

Am I doing something wrong? Any help would be greatly appreciated.

Screen Shot of Project Files Hierarchy Here

AJAX Request Code:

$.ajax({
    type: "get",
    url: "index.html",
    success: function (data) { alert("success" + JSON.stringify(data)); },
    error: function (error) { alert("error" + JSON.stringify(error));}
});

解决方案

You have to append "www/default" before page name, because In windows phone MainPage.xaml is loaded first, which is in root directory. And $.ajax will search from root directory and hence you have to give path as below.

$.ajax({
    type: "get",
    url: "www/default/index.html",
    success: function (data) { alert("success" + JSON.stringify(data)); },
    error: function (error) { alert("error" + JSON.stringify(error));}
});

If your application have too many $.ajax or $.get and you don't want to modify each and every request you can use following global ajax settings when your application starts.

$.ajaxSetup({
    beforeSend: function (jqXHR, settings) {
        settings.url = "www/default/" + settings.url;
    }
});

这篇关于AJAX回调的readyState 4,状态404的Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆