0

I am sending some parameters using XMLHttpRequest. The problem is that one of the parameters comes with many '&' inside and I dont know which one. For example title="abc&foo=324243..." so I dont recieve it completely in php.

       var params = 'id='+mediaPath
    +'&title='+title


    xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if (this.readyState == 4) {


        }
    }
    xhr.onerror = function(e) { 
        console.log(jqXHR, textStatus, errorThrown);
    };
    xhr.open('POST', url);
    xhr.setRequestHeader("Content-Type", 'application/x-www-form-urlencoded');
    xhr.send(params);

I tried like this, but again params are not recieved in php at all:

    xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if (this.readyState == 4) {


        }
    }
    xhr.onerror = function(e) { 
        console.log(jqXHR, textStatus, errorThrown);
    };
    xhr.open('POST', url);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(JSON.stringify({ id: mediaPath, title: title });
Toniq
  • 4,492
  • 12
  • 50
  • 109
  • "The problem is that one of the parameters comes with many '&' inside and I dont know which one. For example title="abc&foo=324243..." so I dont recieve it completely in php." The problem is that you are mashing strings together by hand and not escaping anything instead of using https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams – Quentin Feb 16 '23 at 22:16
  • I am not making this string, it comes from other api and I cannot touch it. It was fine sending it with json using jquery, but I cannot make it work with XMLHttpRequest. On top of all, I dont know any of the values / pairs inside or what its going to have. Are you sure you have answered the question to close it? – Toniq Feb 16 '23 at 22:45

0 Answers0