How to make the search function on a website [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I was just wondering how do I make my website preview some info after the user searches for something stored in the database.

Basic approach for previewing user names as you type in a search bar. For this to work, you will need to use AJAX to query the server and also display the result as a preview for the user to click on if they want, without having to refresh the page.
User types 'Joe' into the search bar
The onChange() even is fired and you query your server with that the user has written "Joe". Keep in mind this query is via AJAX, so as not to force the page to reload.
Server side, you do a MySQL lookup of the table users, where the name is something like "Joe". SELECT NAME FROM USERS WHERE NAME LIKE '%what_you_sent_on_AJAX_request%' LIMIT 10;
The browser receives the response from the AJAX request and displays a nice dropdown with the output of the server. When the user actually click son this "previews" it is in that moment that you would actually reload to the page or take the user to a new page based on what they have clicked on.
That's a very basic approach for it.

Related

detect browser refresh/F5/right click reload in angular 5 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a requirement where, Users inputs something and submit then angular does a service call which returns if users input is valid/invalid. If valid take user to success page, if service returns invalid/bad input then user needs to be taken to failure page and should never be able to go back(using back button) or user refresh the page, user should still be on same page. Only option provided to the user should be close browser, there by not allowing using to submit one more request(leading to service call).
You cannot prevent the user from not running or editing client-side JavaScript code. Since this is a security requirement against the interest of that particular user, the solution must be server-side:
On the server, after getting the wrong answer, mark the user's profile as such. You may need an additional table in your database joining users and questions for that.
Whenever the user loads the question or submits it, first check the user's flag. If it's set, error out immediately.
Note that this behavior is quite hostile to the user. For instance, the user may accidentally touch Enter too soon, and will be shut out by your system.

INSERT into MySQL database with JavaScript but without Node.js [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to INSERT data into my MySQL database.
After some research I found out I can use something called Node.js to do this.
But it seems to complicated for this small thing I want to do.
Is there a way to do this only with JavaScript, without Node.js?
Background: In my web-based iOS app I want to integrate a Favorite button. When the user clicks on the Favorite button on any site some data get stored in my MySQL database (user id, favorited webpage, title of webpage) and the Favorite button changes its color to signal it's favorite and put in the favorite section.
Following problem if doing this with PHP and not JavaScript: The user have to click the Back button twice to get out of this page, because reloading for storing in the database created a new entry in browser history.
Or is there another solution to prevent to the user have to click the back button twice to get out of this page?
Applications which runs on the end-users machines should never-ever have direct database access. Create a REST API with PHP (if you already using it) which handles the database operations and invoke it with JavaScript (this is the short explanation of AJAX).

PHP Elements add EventListener [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm currently working on a website which allows the costumer to personally add movies to a database. So I wrote a PHP class which initially loads all the data needed from a database and creating a table which kind of looks like this:
How do I theoretically proceed to make those buttons work(Which, as they change things in a database should "execute" php-functions).
theoretically this is how you should proceed:
First the database piece
you will create 4 fields
each field corresponding to the table header (notice there should be no space in the name of the field) -- movie_id will be numerical, name will be varchar, etc.
Next the code
I take it the second row are all inside tag? if not make it so
Make sure the form method is POST
I recommend making the action of the form go to another page (keeps it clean)
user clicks on "save changes" button
On the other page (specified in form action), you will receive the data in your $_POST var; based on each input's name, this will be accessible in post. So for example, if your input name for "name" field is "movie_name" then this data will be in: $_POST['movie_name']
Store each field's POST data in a variable... i.e. $movieName = $_POST['movie_name'] ---- THIS IS JUST AN EXAMPLE! YOU SHOULD NEVER ACCESS POST DATA DIRECTLY!! YOU MUST SANITIZE/VALIDATE ETC. THIS DATA BEFORE STORING IN DATABASE
Assuming you have a database link already established, simply insert the data into the table you created earlier
Hope this helps you get started!
Best,
-Rush

Store contents of a <div> to another webpage [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want my users to be able to view content on my website, and when they see content they like (My website randomly generates content using JQuery.load() ), I would like them to be able to store it onto a personal page that they have to log in to, to see.
My page loads content with the line:
$(".resultContent").load(skillList[skillChoice]);
The variable "SkillList" is assigned "skills.html #id"
the '#id' part is identifying a <div>, and that's the part I want to be stored, and I want the user to be able to store multiple parts of the page skills.html on their personal page.
This sounds fairly complex, but I was wondering if it's doable, if so, what language(s) would I need to use?
You will need to save those html snippet on the server, mostly likely in a database. This can be done by client-side javascript, an ajax POST. The server side can use any language.
Since you are saving some html on the server and will load that in a page. The server side must sanitize the html snippets for security.
When the html snippet is saved, the server needs to know who sends the request. That is the user needs to log in before or when s/he saves the content for later use.

Calling form from another website [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I currently have a form which lets the user input 4 fields. What i'd like to know is if it possible to fill and submit a form on a totally separate website with the data that the user previously submitted using the form. If so, how can i do it?
It's possible with direct HTTP post or get requests if the form doesn't have a security mechanism like CSRF tokens. Browsers won't allow users to do that with AJAX if the target website doesn't allow it (Target website is supposed to set a specific header to indicate whether the cross domain requests via AJAX is allowed).
If you want to submit it as soon as the user submits it, just recreate the form with html anywhere you want with the fields. The target url should be the absolute URL.
If you want to submit it later, You can save the submission data in a database and use "cURL" to submit it later with PHP. (more details here)

Categories