简体   繁体   中英

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(); seems to be missing in the second function. That is the default class, so most mobile devices would use that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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