简体   繁体   English

tilda + ajax (post) 或 XMLHttpRequest 手机不要发送

[英]tilda + ajax (post) or XMLHttpRequest mobile don't send

On the desktop version of different browsers, everything works fine, and both methods work.在不同浏览器的桌面版本上,一切正常,两种方法都有效。 But on mobile, none works.但在手机上,没有一个工作。 Pages are fully loaded, there are no errors, everything is also loaded on the mobile version.页面已完全加载,没有错误,所有内容也在移动版本上加载。 Only data is not transferred.只有数据不被传输。 How can you decide?你怎么能决定?

    $(document).ready(function(){
    var user  = ''; // name
    var user2 = ''; // email
    var x     = localStorage.getItem("memberarea_profile");
    var x2    = JSON.parse(x);
    var x3    = window.location; // current url
    var dataString = 'email='+user2+'&name='+ user+'&page='+ x3;

    $.ajax({
        type: 'POST',
        url: 'https://server',
        crossDomain: true,
        data: dataString,
        success: function(responseData, textStatus, jqXHR) {
        },
        error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            alert(err.Message);
        }
    });

    function getXmlHttp(){
        var xmlhttp;
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
        xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
    } 

    var xhr = getXmlHttp();
    //var xhr = new XMLHttpRequest();
    xhr.open("POST", '//server', true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function() {
    if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
        alert('Done');
        }
    }
    xhr.send(dataString);
   });
    
   <?php
   switch ($_SERVER['HTTP_ORIGIN']) {
   case 'http://server': case 'https://server':
   header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
   header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
   header('Access-Control-Max-Age: 1000');
   header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
   break;
   }       
   ?>

the case for new XMLHttpRequest(); new XMLHttpRequest(); seems to be missing in the second function.第二个 function 中似乎缺少。 That is the default class, so most mobile devices would use that那是默认的 class,所以大多数移动设备都会使用它

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

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