这篇文章主要围绕javascript–PhonegapSenchaAndroid:带有基本访问身份验证的ajax请求失败展开,旨在为您提供一份详细的参考资料。我们将全面介绍javascript–Pho
这篇文章主要围绕javascript – Phonegap Sencha Android:带有基本访问身份验证的ajax请求失败展开,旨在为您提供一份详细的参考资料。我们将全面介绍javascript – Phonegap Sencha Android:带有基本访问身份验证的ajax请求失败,同时也会为您带来AJAX请求Cordova / PhoneGap 2.1.0 Android应用程序中的自签名HTTPS资源、android – Facebook Javascript SDK和Phonegap URL错误、javascript - ajax 移动端请求失败??、javascript – Cordova / PhoneGap中的Dropbox.js身份验证的实用方法。
本文目录一览:- javascript – Phonegap Sencha Android:带有基本访问身份验证的ajax请求失败
- AJAX请求Cordova / PhoneGap 2.1.0 Android应用程序中的自签名HTTPS资源
- android – Facebook Javascript SDK和Phonegap URL错误
- javascript - ajax 移动端请求失败??
- javascript – Cordova / PhoneGap中的Dropbox.js身份验证
javascript – Phonegap Sencha Android:带有基本访问身份验证的ajax请求失败
我伙计,
我正在研究Phonegap应用程序和Sencha框架.
我尝试达到protected server但是Android的身份验证失败(但不是iOS).我使用下面的代码:
Ext.Ajax.request({
url:"http://user:password@api.website.fr/query.json",
method: ''GET'',
// I tried to send the header directly but it didn''t work too
headers: {
"Authorization": "Basic s2dh3qs76jd2hqjsdh=="
},
success: function (result, request) {
alert(result);
},
failure: function ( result, request) {
for(var key in result)
alert(result[key]);
}
});
错误消息告诉我需要HTTP摘要…
想知道:
>互联网联系很好
>相同的代码适用于本地文件和其他外部API
>我不知道如何在LogCat中探索Javascript对象,请原谅我恶心的警报(结果[key])
谢谢你们,你们都摇滚!
解决方法:
我同意@Mariano.为什么你不能在浏览器中尝试它,然后部署为带有phonegap的应用程序.可以通过此命令从终端启动Google Chrome来解决跨域问题
google-chrome –args –disable-web-security
有关更多信息,请查看此链接
http://www.senchatouchbits.com/7/cross-domain-ajax-requests.html
总结
以上是小编为你收集整理的javascript – Phonegap Sencha Android:带有基本访问身份验证的ajax请求失败全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
原文地址:https://codeday.me/bug/20190826/1732608.html
AJAX请求Cordova / PhoneGap 2.1.0 Android应用程序中的自签名HTTPS资源
this.setWebViewClient(this.appView,new MyWebViewClient(this));
…到MainActivity类’重写的init()方法,我收到此错误:
The method setWebViewClient(CordovaWebView,MyWebViewClient) is undefined for the type MainActivity
这是MyWebViewClient.java的代码:
package [packagename]; import android.net.http.SslError; import android.webkit.SslErrorHandler; import android.webkit.WebView; import org.apache.cordova.CordovaWebViewClient; import org.apache.cordova.DroidGap; public class MyWebViewClient extends CordovaWebViewClient { public class MyWebViewClient(DroidGap ctx) { super(ctx); } @Override public void onReceivedSslError(WebView view,SslErrorHandler handler,SslError error) { handler.proceed(); } }
这是我的MainActivity.java代码:
package [packagename]; import android.os.Bundle; import org.apache.cordova.*; public class MainActivity extends DroidGap { @Override public void init() { super.init(); this.setWebViewClient(this.appView,new MyWebViewClient(this)); // Error occurs here } @Override public void onCreate(bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setBooleanProperty("keeprunning",false); super.loadUrl("file:///android_asset/www/index.html"); } }
我没有足够的声誉,否则我会对Chris的回答发表评论.此外,我不是在寻找一个jQuery解决方案(我已经知道我可以进行$.ajax()调用来避免这个问题,但我试图将jQuery从我的应用程序中删除).
有任何想法吗?非常感谢您的帮助!
编辑:请在回复之前查看我的评论.
解决方法
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.init(); CordovaWebViewClient webViewClient = new CustomWebViewClient(this); webViewClient.setWebView(this.appView); this.appView.setWebViewClient(webViewClient); super.loadUrl("file:///android_asset/www/index.html"); }
请注意,还需要super.init()
android – Facebook Javascript SDK和Phonegap URL错误
Given URL is not allowed by the Application configuration.: One or
more of the given URLs is not allowed by the App’s settings. It must
match the Website URL or Canvas URL,or the domain must be a subdomain
of one of the App’s domains.
我已经查看了following链接,并完成了链接建议但我仍然在logcat控制台中收到相同的错误
解决方法
javascript - ajax 移动端请求失败??
是这样子的,我用chorme的移动调试可以成功地使用ajax,但是用手机(我的手机是华为mate7)打开执行则失效,这是为什么呢?
<script> $(".cRemind").click(function(){ // 后台下订单提醒功能 var phone = $("#phone").val();//客户填写的电话 var name = $(''#name'').val();//客户名字 var price_total=$(".part_total").html();//商品总价格 var city = $(''#city'').val(); //市 var curr_time = new Date();//下单时间 var times = curr_time.getFullYear()+"年"; times += curr_time.getMonth()+1+"月"; times += curr_time.getDate()+"日"; times += curr_time.getHours()+":"; times += curr_time.getMinutes()+":"; times += curr_time.getSeconds(); var type = $("[attr-select=''1'']").attr("attr-val");//支付方式 var phone_list1 =''137XXX''; var phone_list2 =''137XXX''; $.ajax({ url: ''http://ms.qq.com/sms/remind'', type: "post", data:{phone: phone,name:name,price_total:price_total,times,times,city: city,type:type,phone_list:phone_list1}, dataType: "jsonp", cache: false }); $.ajax({ url: ''http://ms.qq.com/sms/remind'', type: "post", data:{phone: phone,name:name,price_total:price_total,times,times,city: city,type:type,phone_list:phone_list2}, dataType: "jsonp", cache: false }); }) </script>
回复内容:
是这样子的,我用chorme的移动调试可以成功地使用ajax,但是用手机(我的手机是华为mate7)打开执行则失效,这是为什么呢?
<script> $(".cRemind").click(function(){ // 后台下订单提醒功能 var phone = $("#phone").val();//客户填写的电话 var name = $(''#name'').val();//客户名字 var price_total=$(".part_total").html();//商品总价格 var city = $(''#city'').val(); //市 var curr_time = new Date();//下单时间 var times = curr_time.getFullYear()+"年"; times += curr_time.getMonth()+1+"月"; times += curr_time.getDate()+"日"; times += curr_time.getHours()+":"; times += curr_time.getMinutes()+":"; times += curr_time.getSeconds(); var type = $("[attr-select=''1'']").attr("attr-val");//支付方式 var phone_list1 =''137XXX''; var phone_list2 =''137XXX''; $.ajax({ url: ''http://ms.qq.com/sms/remind'', type: "post", data:{phone: phone,name:name,price_total:price_total,times,times,city: city,type:type,phone_list:phone_list1}, dataType: "jsonp", cache: false }); $.ajax({ url: ''http://ms.qq.com/sms/remind'', type: "post", data:{phone: phone,name:name,price_total:price_total,times,times,city: city,type:type,phone_list:phone_list2}, dataType: "jsonp", cache: false }); }) </script>
按照你说的是在chrome中使可以的,但是在移动端就不行了。如果有抓包工具可以调试下, 请求是否异常等等。如果没有抓包工具,可以在代码中加入几个提示性的动作比如说alert(),在ajax中添加回调函数等等来进行调试,应该是很容易发现问题出在哪的。
ps: 还有两个建议就是你的下单总金额从前台传的话不安全,这个应该是服务端计算才好一点吧;第二个就是时间可能的话可以在服务端在进行入库,毕竟本地时间不知道是不是准确的。(个人建议哈)
javascript – Cordova / PhoneGap中的Dropbox.js身份验证
我正在Cordova / PhoneGap中编写一个应用程序,它试图使用DropBox.js从DropBox获取文件. Cordova版本为3.0.1,DropBox.js版本为0.10.0.我的Javascript在桌面浏览器上工作得很好:
var client = new DropBox.Client({ key: "<my key>", secret: "<my secret>"} );
client.authenticate(function(error, client) {
...
但在Cordova打包的应用程序中,我收到一个错误:“您使用的应用程序似乎提交了一个错误的请求”.
我怀疑这个问题与在Cordova应用程序中解决此问题的redirect-url有关:
DropBox.AuthDriver.browserBase.currentLocation()
-> file:///android_asset/www/index.html
即使我将其添加到DropBox API控制台中的OAuth重定向URI,使用文件:///开头的网址也无法正常使用DropBox API.
如果我之前知道uid和令牌,Cordova应用程序可以正常工作:
var client = new DropBox.Client({
key: "<my key",
secret: "<my secret>",
token: "<token>",
uid: "<uid>"
});
client.authenticate(function(error, client) {
...
这样我就能很好地阅读我的DropBox文件.问题是令牌不会永远存在,我想从我的应用程序本身获取一个新令牌.
根据this discussion,这个问题应该已经在早期版本的dropBox.js(0.9.2)中得到解决.但我仍然遇到它.我想知道我是否应该使用API有点不同,但我不知道如何.
DropBox.js添加了一个redirectUrl选项in this commit我只是不知道我应该在Cordova应用程序中放置什么. file:///android_asset/www/index.html不起作用,因为DropBox API不允许文件网址.
Simon McDonald对this question的回答可能有所帮助.但这意味着我必须拥有一个带有dropBox.js登录功能的外部服务器托管页面.或者我可以使用主DropBox Web登录页面吗?
解决方法:
dropBox.js 0.10.1对Cordova有一些修复.
我们刚刚设置了一个页面,当file://不起作用时,您可以将其用作嵌入式WebView中的OAuth 2重定向URL.
https://www.dropbox.com/1/oauth2/redirect_receiver
今天关于javascript – Phonegap Sencha Android:带有基本访问身份验证的ajax请求失败的介绍到此结束,谢谢您的阅读,有关AJAX请求Cordova / PhoneGap 2.1.0 Android应用程序中的自签名HTTPS资源、android – Facebook Javascript SDK和Phonegap URL错误、javascript - ajax 移动端请求失败??、javascript – Cordova / PhoneGap中的Dropbox.js身份验证等更多相关知识的信息可以在本站进行查询。
本文标签: