M
M
mmka2014-01-27 02:43:57
JavaScript
mmka, 2014-01-27 02:43:57

Ajax or Angular filtering?

Just a few questions. Here is an example angular.github.io/angular-phonecat/step-4/app . Understandably looking for. How to implement filtering like in online stores using selects and radio buttons? And what is this anyway? Is it just looking for tex? Or creates certain queries to the database? And if you use real filtering together with php, how can you do it in an online store? I just need it in real time. Maybe better then ajax'om. Explain to me please. How to compose a request to insert the response into the DOM, but before that show the loader? Sorry, I do it somehow in php, but I never worked with ajax. That's why such stupid questions. And I still want to sleep at 4 in the morning

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GM2mars, 2014-01-27
@mmka

Write: (AngularJS)

var value=5;
$http({method: 'POST', url: server_side.php?action=get_item, data: value}).success(function(res) {
  $scope.items=res;
}).error(function(res) {
  alert("Ошибка");
});

We send "Angular request" to the server. method - request type (get, post), url - page for request processing with some parameter. If it is post, then we pass the value in the body. The function returns res variable (any name) in which the response from the server. We process the response as we need. In case of an unsuccessful response, we show an error.
If you want to search in real time, then the algorithm is as follows:
When you press a key in the input field, we take the value of this field and send it to the server using the method indicated above. On the server, we catch this request, process it (for example, look for the name in the database by the incoming value) and display the answer with the usual echo, having previously translated it into a convenient form (or a ready-made html piece or json string)
Well, on the client, accordingly, we should have a prepared function for processing the response, for example, generating a list of found ones.
For real-time search, I advise you to start the search (send requests to the server) from 3 characters, well, 1 second after pressing the key.

Q
Quber, 2014-01-27
@Quber

If you have never worked with ajax, then it is better not to look at Angular yet. Understand jQuery and its $.ajax method If you worked with js, and even more so with jquery, then there will be no problems, everything is easily configured and written.
I would not recommend filtering like in an online store through Angular, since Angular uses js to display data, which is not good for search engines. And first of all, you need your content to be seen and easily indexed by search engines.

S
Sergey, 2014-01-27
Protko @Fesor

the server should be responsible for the lookup. angular just needs to collect the data for the request (what to filter by) and send the get request through the $http service.
In fact, it all comes down to data-binding the form, which would then take the data and request search results from the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question