I thought it would be a great idea to let our associated dealers have the opportunity to have this on their own site as a widget. https://www.autopower.no/ ("Effektoversikt" to the right).
The "effektoversikt" fetches data from our MySQL database. Once the user finds their car and clicks "søk!" (search) they should be redirected to our page...
I'm thinking using iframe- or script-tags is the solution?
could someone point me in the right direction on where to start?
this could be a div element fed by a ajax request. The ajax request returns html snippet as search form, and when you submit, result is sent by website that generated the ajax request (so it looks like a redirect for the end user).
[edit]
Source website has an url that creates a HTML snippet as <form>...</form>. Say, not an HTML page, only the form.
target website uses, for example, JQuery to fetch the form via an Ajax request and set the html snippet into a div in target's website. As the form target is on the source website, a submit on the form automatically forward to that source site.
So create first a script/whatever that exposes the HTML snippet, then try to insert it into another page. You can experiment insertion part on JSFiddle.
Related
I'm trying to find a way for PHP to press the "submit" button on a PHP form on a live webpage.
I need to do this as I am unsure as towards what data is send through this form, as it is a post form and the API is closed source.
Is there anyway to send a jQuery like click command to a live webpage through PHP at all?
Nothing needs to be retrieved from this form, only needs to have pressed the button correctly.
EDIT
More context:
Yes, the site is 3rd party (this is why I can't simply look up something on any API documentation), the program is downloading a gallery of images through the in-site gallery archiver. Previously the URL for this gallery's archive was stored on a simple popup window page's source. Now however you must confirm it first the page reloads (after a form submits through POST) onto the same page (archiver.php) and the download starts. This reloaded page contains the URL of the file. Nothing is submitted beyond the users confirmation to the download manually, perhaps something in the back end is sent upon this, I don't know.
EDIT 2
I've fixed this by figuring out what the form submits.
I think it is not possible to click a button on another page with php or jquery.
But you can analyse the form and find out the destination URL and send a own request. If it is GET it should look like this: myhomepage.com?id=1&name=foo&password=hello123
you have to use jQuery or javaScript For pressing submit button on live page dynamically. PHP is server side script and from is client side so its not possible. but if you want to read data from live webpage than you have to use cURL or file_get content
This is kind of hard to explain but i'll do my best to explain it and maybe someone knows what i'm trying to do.
I have a dashboard.php page and within that page i have a main-interface div that covers 100% width underneath a nav a header.
This dashboard when the user clicks a link changes the content of main-interface div with data from another page for instance search user.
I can load the search user page into the main interface fine but the problem I have is when I click search user it takes me back to the dashboard.php page with the original main-interface content rather than a table of all the users I searched.
I am having trouble telling the jquery that I want it to search for users and populate it back into the main interface page after the search user link was clicked.
Hope some one gets the idea of what im doing and trying to accomplish.
You could split tasks into client tasks and server tasks.
Client tasks are things that javascript/jQuery will do on the browser.
And server tasks are things that your server will do when requests get in.
This does not mean that the server will need to create full html pages, just send some information to the client bypassing a full page creation.
I often do something like:
<script>
var send = { };
send[ 'find' ] = $("input[name='find']").val();
send[ 'token' ] = $("input[name='token']").val();
$.post( 'request.php', send, function( data ) {
$("#name").html( data );
});
</script>
There are some options on the data you will get from the request.php.
You can let request.php create html that you can put into a <div id="name">.
Or write client side code that creates HTML from JSON.
Hope it makes sense.
i have a website that uses a number of containers (div's). In this scenario, we have three boxes down the left side and one bigger box on the right of these boxes. The bigger box on the right is the only thing that changes when a link is pressed, this is done with Javascript.
SO i have the index which is the main layout of the website and i also have the "pages" of the site, so when a link is pressed the main box (on the right) loads the new data.
On one of my pages i want to collect data and then run it through a PHP script that is in the head of the file, but when i click the button i realise it refreshes the whole page and it doesn't run the script on the page with the form.
Anyone had a problem like this, or know of something i could do to work around it?
I'm not really sure what code would be useful for helping me but if you need something just ask.
Thanks for the help
Since you are loading all your content via JS already, you could just POST the form data via AJAX to a PHP script to process, then read the output and either provide an error message or remove the form from the page and show your success message.
How to approach your AJAX call is dependant on what you've used as a basis for the rest of your JS.
Personally I like to use the JQuery library, as it makes AJAX calls (and much more) very simple.
How about you make the page design able to do it. Have the backend be able to spit out the state of the page when it posted.
Or use Ajax to post the data back and set the new state like you do already.
What I have is a search form that submits to the same page and it fetches the results using an AJAX request.
This uses the POST method and I am trying to figure out a way to try and do something along the lines of having a button to open this page in a new window to preserve the search parameters and results and to allow it to be bookmarkable somehow but I can't really think how to do this.
The other main reason for doing this is because the search results contain links to if a user clicks one and then clicks back all the form parameters are lost, I have worked around this by having the links open in a new window.
Any help, advice and opinions would be much appreciated.
If you do a GET method instead of POST, then the user will get to an URL with its form parameters in it.
It won't have to be ajax anymore
I am tweaking a website to make it easier for employees to edit products. Right now, someone has to login to the DB and change prices, and then someone has to change the physical html of the website itself.
So I am writing code that pulls all the products off the DB, and displays them on a page which can be edited. I think doing everything with Ajax would be best.
ajaxRequest.open("GET", url, true);
ajaxRequest.send(null);
The problem is, I only know how to process Ajax requests using a URL (using POST, GET, etc). I need help writing the code to pull the info off the DB, and display it.
The table name is PRODUCTS. Within PRODUCTS are the columns ID, STOCK, SHORTNAME, DESCRIPTION, PRICE and SHIPPING.
In the HTML, I have a div setup:
<div class="product">
<div class="productName">
SHORTNAME, PRICE, SHIPPING
</div>
<div class="productDesc">
ID, DESCRIPTION, STOCK
</div>
</div>
I want to set it up so if I click a button, ajax pulls all the information off PRODUCT, and creates .productName div. If the user clicks .productName, it will then further expand to reveal .productDesc.
Question: How to I query the DB using AJAX on a button click, and put the information into elements?
Ajax cannot access your database. Ajax simply loads content from a URL. Your application must do this, and provide the result to an ajax call.
Here's how it will work.
Browser open a url on your server
PHP renders a page for display on the browser
User clicks something
Javascript sends an Ajax request to your server
PHP recieves this request and queries the database
PHP renders a response for the request
The Ajax handler on your page receives this response as plain text and does something interesting with it (such an inserting HTML, evaluating JSON, or executing javascript)
Ajax is just a way to load the response from a URL without actually navigating your browser to that page. It does not (and should not) have any sort of direct database access. In fact it has no idea there is a database at all.
Imagine the security issues if any javascript could read or write any field in your database. it would be a hackers dream.
You have to write a PHP script that queries the database and returns the results either as JSON or HTML.
This script is called via jQuery. E.g.
$('#main').load('http://your-url.com/yourscript.php');
This loads the output generated by yourscript.php (given that it is HTML) into an element with ID main.
You can find an Ajax tutorial with jQuery here. And a lot more tutorials on the jQuery tutorials site.
PHP - actually, it seems to be no job for jquery - once somebody edits it in DB, app gets latest information every hit.
Unless I misinterpreted your question, I see nothing this has to do with jQuery/AJAX.