简体   繁体   English

iPhone短码xmlhttprequest没有响应

[英]iPhone dashcode xmlhttprequest no response

I'm developing an iPhone web app with dashcode. 我正在开发带有破折号的iPhone Web应用程序。 My app runs fine when I browse it with the iphone simulator. 使用iPhone模拟器浏览时,我的应用程序运行良好。 When I deploy it to a web-server, I never get a response from XMLHttpRequests. 当我将其部署到Web服务器时,我从XMLHttpRequests都没有得到响应。 Here's the code I use: 这是我使用的代码:

function get(feedURL, handler) {
    var onloadHandler = function() { handler(xmlRequest); };    
    var xmlRequest = new XMLHttpRequest();
    xmlRequest.onload = onloadHandler;
    xmlRequest.open("GET", feedURL);
    var credentials = encodeBase64(_login.username + ':' + _login.password);
    xmlRequest.setRequestHeader("Authorization", "Basic " + credentials);
    xmlRequest.send();
}

When I attach a onreadystatechange handler, I can see the the request goes to state 4. I can also see the requests in my server logs. 当我附加一个onreadystatechange处理程序时,可以看到请求进入状态4。我还可以在服务器日志中看到请求。 I also added a "no cache" request header, which didn't help. 我还添加了“无缓存”请求标头,但没有帮助。 I tried this on a local web-server on a hosting package that I have and I don't have any luck getting it to work. 我在本地托管服务器上的Web服务器上尝试了此操作,但我没有运气让它正常工作。

A shot in the dark, but the apple docs say this. 在黑暗中开枪,但是苹果医生说了这一点。

the domain of the URL request destination must be the same as the one that serves up the page containing the script. URL请求目标的域必须与为包含该脚本的页面提供服务的域相同。 This means, unfortunately, that client-side scripts cannot fetch web service data from other sources, and blend that data into a page. 不幸的是,这意味着客户端脚本无法从其他来源获取Web服务数据,也无法将该数据混合到页面中。 Everything must come from the same domain. 一切都必须来自同一域。 Under these circumstances, you don't have to worry about security alerts frightening your users. 在这种情况下,您不必担心安全警报会吓倒您的用户。

What are the values of status and statusText? status和statusText的值是什么? Also try getAllResponseHeaders() for more info. 也可以尝试getAllResponseHeaders()获取更多信息。

Also, if it's just basic auth you want, you can just pass it to open() like so: 另外,如果它只是您想要的基本身份验证,则可以将其传递给open(),如下所示:

open("method", "URL", asyncFlag, "userName", "password")

The iPhone probably isn't expecting to receive Basic Auth headers, since you manually set the request header. 由于您手动设置了请求标头,因此iPhone可能不希望接收“基本身份验证”标头。 Try adding the username and password to the URL (after percent encoding) and run the request that way. 尝试将用户名和密码添加到URL中(在百分比编码之后),然后以这种方式运行请求。

Maybe try the new debugging capabilities that are part of DashCode 3.0 (new with Snow Leopard)? 也许尝试DashCode 3.0(Snow Leopard的新功能)中包含的新调试功能? Not really an answer, but perhaps a change of scenery -- or the new debugger -- will shake something loose. 这并不是一个真正的答案,但是也许景色的改变-或新的调试器-将会使事情有些松动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM