Pull data from database on click? [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 8 years ago.
Improve this question
I was wondering whether it is possible in JavaScript (preferably jQuery) to pull data from a database using MySQL after clicking on a button? I currently pull data when the page loads, but I don't want to load 100's of items at the beginning as I want to be able to pull certain rows with different buttons?

<button class="AjaxTrigger" data-example="abc">I do ABC </button>
$('.AjaxTrigger').on('click', function(){
$.get("your-file.php", {example: $(this).data('example')}, function(result){
alert( "This is what php gave me: " + "\n" +result );
}
});
And now you let your-file.php do whatever you want, just like you normaly program you php files. Echo the outcome, and in javascript you will get exactly that in the returnfunction (which now alerts your result).
jQuery's full ajax, or jQuery's get (works easier)
Using jQuery to access data-* attributes
jQuery's eventhandling explained (event are eg: click, hover, keyup)
When to use GET or POST (<- Good to read for everyone)
And if you feel like upping your game:
Use jQuery's getJSON to send back an array to javascript ( echo with php's json_encode())

Related

Click an element on one page and change an element on another page JQUERY [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 3 years ago.
Improve this question
I'm attempting to click a button on a page (index1.html) and I want it to modify the color of some text that is actually on another html page (index2.html). Is this possible to do with jquery?
Everything I've tried doesn't work and I understand why: since to view the second page (index2.html), I need to refresh that page, the action is lost during that refresh. I know this can be done with angular or react but i really want to stick with jquery or javascript only.
Is this possible?
One option I can see is when navigating to index2.html, is to pass some query params. For example: ./index2?something=true&otherthing=false. Then use js to get the query params on page load.
var searchParams = new URLSearchParams(window.location.search);
searchParams.get("something"); // true
For reference
It can't be achieved directly neither with jQuery nor with React/Angular/vanilla JS.
You have 2 options both related with storing data.
Use localStorage or sessionStorage (or well cookie if you prefer and it makes sense).
Just store the information you want to pass in index1.html then check if it exists on index2.html, if so, use it.
Use backend
It's actually quite similar to the firs option but slightly more reliable (even though much more complex).
In this case, once the button on index1.html gets clicked, set a cookie with needed data/send data directly to the server with HTTP request.
This way you will have to play with data mostly on the server side.

Copy the query of GET to clipboard [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
Is it possible to copy the query of a form, which is using GET method, to the clipboard?
My aim is to have a button, which when pressed should copy the value in the black box to the clipboard so it is easily shared with someone else.
Edit: Not just asking about copying something into the clipboard, I am also asking about how to get the value of the GET query..
The GET parameters are only added to the submitted URL at the moment where the button is pressed, i.e. the form is submitted, so I don't think that 's possible directly (i.e. retreiving a value from the submit button)
But you could use a plugin like https://clipboardjs.com/, "collect" all the form data via JS and combine them together with the initial URL for its return value including the GET data.
this might help
var path = location.href.replace(/[^\?]+$/,$('form').serialize());
var cpy = $('input#cpy').val(path);
cpy.select();
document.execCommand('copy');

Autofilling a different webpage with user input [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 am trying to find out how I can make a program in JavaScript/HTML that takes a user's input and automatically enters this information onto a different web page. I am new to JavaScript/HTML so any help would be appreciated!
You specified the website as:
Supreme
Now, when you go to checkout, right click and click Inspect Elements. Then find all of the input fields on the website. For example, I found the Full Name input field. The field has a name: order[billing_name]
What you want to do next is in your URL do something like this:
https://www.supremenewyork.com/checkout?order[billing_name]=yourname
Now if you want multiple values (most likely) you need to find the names of the other fields and add the values to the URL, as so:
https://www.supremenewyork.com/checkout?order[billing_name]=yourname&order[email]=youremail
This way you can pass the values from your application and fill in the form on that website.
Hope this helps.
Use localstorage. see working demo in the link below;
Note: localStorage won't work in snippet; hence I made a fiddle.

ASP.NET change text with no page refresh on button click [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've found a couple other threads containing the same questions, but none of them had an understandable answer. I am supposed to make client side changes, but that is only possible in the .ascx file and if for instance i want to call a function to calculate something and then display it with no page refresh that is not possible :( any easy solutions?
With jquery, you can replace the contents of any existing HTML element using the .html() function. For example,
$("#MyDiv").html("Here is the new text.");
Since the function takes HTML as an input, you can even set the style if you want:
$("#MyDiv").html("Here is some text. <DIV class='foo'>Here is some more text in a different style.</DIV>");
You can also add new elements using .append(), like this:
$("#MyDiv").append("<p>Even more text</p>");
To do this upon a button click, you would use the .click() function. So your code would look something like this:
$("#MyButton").click(function() {
$("#MyDiv").html("You just clicked a button!");
});

What is the best way to generate HTML using PHP & JQuery [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I've got a setup of HTML, PHP & jQuery. The steps I want the user to take are as follows:
Click a button
Modal Appears with dynamic data (taken from button markup, parent div etc.)
User Submits Modal & Close
I have two options. To:
Generate the HTML prior the user clicking the button. With PHP & Just hide it & then manipulate it with jquery once clicked.
Request the the HTML on click via Ajax using an API & again manipulate it with jQuery.
My question is. From the two options which would be the best for performance?
Reading through this and documenting my logic. I'd say that point 1. would be best as I'm not requesting a large amount of data through the API every time?
Can anyone see any advantages to number two? Apart from not requesting the data server side on page load?
Thanks.
I think the main question here is "how dynamic is the information used to produce that HTML ?".
If there isn't any high probability that the information used to produce that HTML could change at any time, then you should better off with 1st option, since therefore you will be avoiding an additional request to the server.
If the information used to produce that HTML could change at any time, that would be the reason to use the 2nd approach.

Categories

Resources