A. L
A. L

Reputation: 12649

rxjs-dom how to pass data into POST

I'm using rx.DOM.ajax https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/doc/operators/ajax.md

I'm trying to get some data from a url using POST but it doesn't return anything.

Here's the code:

Rx.DOM.ajax({
    url: 'src/php/search.php',
    method: "POST",
    body: {
      extra: "Extra"
    }
  });

If I print_r($_POST) there's nothing in it. I'm expecting the server to receive a $_POST.

Upvotes: 2

Views: 362

Answers (1)

A. L
A. L

Reputation: 12649

Since rxjs-dom wasn't working I found another way.

Don't use rxjs-dom. It might be out of date. I went to use rxjs instead. Here's what I did (utilises jquery).

From my situation:

var search_bar = $("#search");
var textInput = $(search_bar);
var throttledInput =
      Rx.Observable.fromEvent(textInput, 'keyup')
        .pluck('target','value')
        .filter( function (text) {
            return text.length > 2;
        })
        .debounceTime(500)
        .distinctUntilChanged();

var suggestions = throttledInput.switchMap(term => term ? this.search(term) : "no term");
suggestions.subscribe(
  function (data)
  {
    console.log(data)
  },
  function (e)
  {
    console.log(e);
  }
);


search(value)
  {
    return $.ajax({
      type: "get",
      url: "src/php/search.php",
      data: {
        name: value
      }
    }).promise();
  }
  • First it gets the value from one of my inputs.

  • Then it turns it into an observable from the value.

  • debounceTime is used to prevent flooding the server if you're typing quickly

  • distinctUntilChange is used so only new results are sent

  • Lastly, it can utilise jquery, but must convert it back to promise.

Upvotes: 0

Related Questions