Welcome Guest, Not a member yet? Register   Sign In
Controller is firing but I can't get the $_GET
#5

(This post was last modified: 03-21-2018, 02:27 PM by dave friend.)

You can send data back from a POST too and it is done identically to the way you would respond to a GET. It's only AJAX after all.

You'll want to add handling to the JavaScript.

Code:
document.onreadystatechange = function () {
   if (xhr.readyState === 1)
  {
       xhr.send(json);
   }
   if (xhr.readyState == 4) // DONE
  {
       doSomethingWith(xhr.response);
   }

You can also use event listeners to handle readyState changes. Here's one for DONE a.k.a. xhr.readyState == 4

Code:
xhr.addEventListener("loadend", callbackFn, false);

Where "callbackFn" is a function to handle the response. It can be an in-line anonymous function too.

And if you really, really, really insist on using get the way to pass data is to construct your url complete with a query string.

Code:
var url = 'http://localhost/Subit_backend/register' + '?email=' + jsonResponse["email"];  // if jsonResponse["email"] is a string
xhr.open('GET', url, true);
Reply


Messages In This Thread
RE: Controller is firing but I can't get the $_GET - by dave friend - 03-21-2018, 01:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB