Jump to content

ava_barbilla

Members
  • Content Count

    47
  • Joined

  • Last visited

Community Reputation

0 Neutral

About ava_barbilla

  • Rank
    Newbie
  1. Thank you justsomeguy. I will change the functions interval to 2 seconds and will find out a way to summarise this process. Once I get any positive feedback from this entire process I will let you know. King regards once again!!
  2. I did so, and this helped this move a step forward. Now the value refreshes, but sadly, it refreshes every second although data in the php file has not changed. I will give you some details in terms of my entire process. I use WP Web Scraper which is a plugin for WordPress which scrapes data from a website and displays it on your website using shortcodes or php code. I use this plugin to scrape a data from a website (This is to give you an overall view of what I am doing). My php file contains this: <?phprequire('../../wp-blog-header.php'); //I use this to load the WordPress environment into my PHP file to execude code such as "echo do_shortcode" which is the case in this scenarioecho do_shortcode( '[wpws url="URL" query="body %3e table %3e tbody %3e tr:nth-child(1) %3e td:nth-child(8)" querydecode="1" ]' ); //Assume URL is the actual link to the site?> What this is resposible for is loading the data into an external PHP file (called "test.php") which I can the load afterwards into my WordPress page. If I open this file in my browser using my localhost it works fine, displaying the data and if I use my Inspector the source code is as follows: <!-- Start of web scrap (created by wp-web-scraper) Source URL: http://www.example.com // Link to the website Query: body > table > tbody > tr:nth-child(1) > td:nth-child(8) (cssselector) Other options: Array( [headers] => [cache] => 0 [useragent] => Hello World [timeout] => 2 [on_error] => error_hide [output] => html [glue] => [eq] => [gt] => [lt] => [query_type] => cssselector [remove_query] => [remove_query_type] => cssselector [replace_query] => [replace_query_type] => cssselector [replace_with] => [basehref] => 1 [a_target] => [callback_raw] => [callback] => [debug] => 1 [charset] => UTF-8 [url] => http://ww.example.com //Link to the website [query] => body > table > tbody > tr:nth-child(1) > td:nth-child(8) [urldecode] => 1 [querydecode] => 1)--><html><head></head><body>987654.321 // The price (or data) goes here<!-- End of web scrap WPWS Cache Control: Remote-fetch via WP_Http Computing time: 0.9369 seconds--></body></html> This is not to worry about, as when I directly paste the code (provided by the plugin) into my website the data appears. The data gets extracted accurately and correctly. With this, however, you never know when the data changes so I try to check every second if perhaps "987654.321" has changed to maybe "987654.322" or something similar, and if this is the case refresh the div. When data is scraped, automatically comments are included in the HTML output. When I insert the script into my WordPress page now with the changed version: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script>$(document).ready(function () { $('#demo').load('http://localhost:8888/test-site/wp-content/my-php-files/test.php'); var auto_refresh = setInterval( function () { var result = null; var div = $('#demo').html(); $.ajax({ url: 'http://localhost:8888/test-site/wp-content/my-php-files/test.php', type: 'get', dataType: 'html', success: function (data) { result = data; if (Number(result) != Number(div)) { // Included "Number()" as I am dealing with numerical data to see if it works. Unfourtunately it does not. $('#demo').fadeOut('slow', function () { $('#demo').load('http://localhost:8888/test-site/wp-content/my-php-files/test.php', function () { $('#demo').fadeIn('slow'); }); }); } } }); }, 1000);});</script><div id="demo"></div> the div is still refreshed every second eventhough the data has not changed. I tried so much, but it seems like the script is unable to compare the values, or simply sees them as different the entire time so it uploads the div. After the script is executed in my WordPress site, my "Inspector" shows the following code: <div id="demo" style="display: block; opacity: 0.654508497187474;"> //Here opacity keeps changed to fill the fading effects criteria, which means the div blinks the whole time.<!-- Start of web scrap (created by wp-web-scraper) Source URL: http://www.example.com Query: body > table > tbody > tr:nth-child(1) > td:nth-child(8) (cssselector) Other options: Array( [headers] => [cache] => 0 [useragent] => Hello World [timeout] => 2 [on_error] => error_hide [output] => html [glue] => [eq] => [gt] => [lt] => [query_type] => cssselector [remove_query] => [remove_query_type] => cssselector [replace_query] => [replace_query_type] => cssselector [replace_with] => [basehref] => 1 [a_target] => [callback_raw] => [callback] => [debug] => 1 [charset] => UTF-8 [url] => http://www.example.com [query] => body > table > tbody > tr:nth-child(1) > td:nth-child(8) [urldecode] => 1 [querydecode] => 1)--><td>987654.321</td> //Example data<!-- End of web scrap WPWS Cache Control: Remote-fetch via WP_Http Computing time: 0.9416 seconds--></div> I am truly sorry for bombarding you with so much information. I thought that every detail may help. The script loads everything from the PHP file, including the comments. Do the comments have to do with this going wrong? I have got no idea. Many thanks to both of you who always help me out!!
  3. I followed your advice use "console.log" and when I go to the inspector ("Console Tab"), nothing appears and when the page is refreshed still the console is empty.
  4. I get no error from the server. I simply get nothing. This I think means that the "if" operator has the error or no data is transferred, however, in my first code it worked so I suppose this has to do with the "if". I tried changing this to another code which looks like this: $(document).ready(function () { $('#demo').load('http://localhost:8888/test-site/wp-content/my-php-files/test.php'); var auto_refresh = setInterval( function () { function testing() { var result = null; var div = $('#demo').html(); var scriptUrl = "http://localhost:8888/test-site/wp-content/my-php-files/test.php"; $.ajax({ url: scriptUrl, type: 'get', dataType: 'html', success: function (data) { result = data; if (result != div) { // Here you can see I changed the criteria $('#demo').fadeOut('slow', function () { $('#demo').load('http://localhost:8888/test-site/wp-content/my-php-files/test.php', function () { $('#demo').fadeIn('slow'); }); }); } } }); } }, 1000);}); This, however, still does not work. Nothing appears just as before. To be honest, I go no clue as to what is going on. In my last topic I was trying to figure out on how to load the div and it resulted in something very strange and Ingolme was confused as to what my server was doing as well. In order to load the code, given that I use WordPress, I had to load the WordPress environment inside the PHP file. It loads perfectly, but once I set the criteria to refresh the div only if the value has changed, I get no response and my div is empty. Is the script unable to compare the values? Should I stick with this code or with the previous one? Thanks so much again for bearing with me.
  5. Ok I understand. I utilised: $.ajax({ url: scriptUrl, type: 'POST', // I tried "GET" as well dataType: 'html', async: false, // Note here I used a synchronous request However, just as you stated that the browser pauses, my browser started to run very slow so I decided to delete it. I rearranged my structure as follows: $(document).ready(function () { var auto_refresh = setInterval( function () { function testing() { var result = null; var scriptUrl = "http://localhost:8888/test-site/wp-content/my-php-files/test.php"; $.ajax({ url: scriptUrl, type: 'get', dataType: 'html', success: function (data) { if (data.changed) { $('#demo').fadeOut('slow', function () { $('#demo').load('http://localhost:8888/test-site/wp-content/my-php-files/test.php', function () { $('#demo').fadeIn('slow'); }); }); } } }); } }, 1000);}); Now, however, nothing appears. Does this has to do with "data.changed" I used in my if operator? Regards!!
  6. In my previous question I managed to solve a way to load an external php file into my html thanks to your help. The php file loads perfectly fine as long as it follows the simple to criteria to load php after a given amount of time, which in my case is 1000 milliseconds. I wanted to know a method which loads data from the php file ONLY, and ONLY if the data in that php file has changed. My script what I managed to do after hours of research looks like follows: <script type="text/javascript">$(document).ready(function () { var auto_refresh = setInterval( function () { function testing() { var result = null; var scriptUrl = "http://localhost:8888/test-site/wp-content/my-php-files/test-check.php"; //Use this php file (NB: This file contains the same data as "test.php") as a check if data changed or not. $.ajax({ url: scriptUrl, type: 'POST', // I tried "GET" as well dataType: 'html', success: function (data) { result = data; } }); return result; } databaseData = testing(); currentData = $('#demo').html(); if (databaseData != currentData) { // I compare the values from the Ajax request and the value currently in my div to see if they are similar or not. $('#demo').fadeOut('slow', function () { // I added fadeOut and FadeIn effect for the div to load when data has changed $('#demo').load('http://localhost:8888/test-site/wp-content/my-php-files/test.php', function () { $('#demo').fadeIn('slow'); }); }); } }, 1000);});</script><div id="demo"></div> In this case scenario, the problem is that the div is loaded every second with the fadeIn and FadeOut effect although the data has not changed. Precisely, the same value appears even up to ten times with the effects even if it is the same value the whole time. It does not matter, if the value is altered or not, the div will be refreshed anyway. The php file contains some data (to pe precise prices) that are refreshed in a random amount of time (it can be 1 second, 10 seconds, 1 minute, etc; this is uncertain). Is there a way to compare the data in "test.php" and if it is not the same, upload the div with the new content? Thanks once again!! This forum always gives great support and positive feedback.
  7. I added some html to the php file and everything loads except the php file (php appeared as a comment). Then, I came up with the idea to compare the php file I created with the other php files on my local server. I identified a little difference. The other php files do not close the php, i.e. <?php echo 'Hello World'; without putting "?>" at the end, and now it works. My php file looks like this: <?phpecho 'Hello World'; I also simplified my script, making my structure look like follows: <div id="demo"><div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script>$(document).ready( function() {$('#demo').load('http://localhost:8888/test-site/wp-content/my-php-files/test3.php');});</script> I used JQuery .load() property as it is simpler than the normal script (same principle). The only thing I have to do now is to apply a setIntervl to load the function after a specific amount of time and I am finished. Thanks for the support Ingolme. I learned a lot today with your help.
  8. Yes, I tried that already. I tried renaming the file and other tricks as well. How can I upload pictures here? Maybe I can send some screenshots so that you can see how my localhost looks like and some other screenshots which may be of use furthermore. Moreover, when I click on "Inspect Element", go to the network tab and click on refresh I can see all the movement that happens. One of them is the the Ajax Request with the type "POST" and Status 200 (OK). I have been doing some research but sadly I found nothing useful regarding this subject. Does it have to do with the fact that I use Caching Plugins? I use W3 Total Cache in order to cache browser data, minify scripts, etc. I also use an Autoptimize tool that optimizes HTML, CSS, and Javascript but I doubt that this last tool has anything do with as all other scripts work, and in this case scenario the script seems to be working fine. To be honest this is a mistery to me.
  9. Ok, I have tried that as well. Still the same. The browser does not process the php and just displays <?php echo 'Hello, World!'; ?> instead of showing "Hello World".
  10. I use localhost if not any page would not be loaded. I was not sure which url you needed so I provided both. My Ports are as follows: Apache Port: 8888 Nginx Port: 7888 MySQL Port: 8889 My PHP version is 5.6.2 and my Webserver is Apache. Hope this helps, as perhaps this problem ay have to do with the ports. What would you suggest?
  11. Yes, indeed. The complete URL of the file is in the javascript code.
  12. No I have managed to get the link published. Really sorry about that.
  13. "view-source:file://localhost/Applications/MAMP/htdocs/test-site/wp-content/my-php-files/test.php"
  14. THis is the link when I open the file directly from my documents:
  15. Sorry for the blank posts. There is an issue the link does not get published!
×
×
  • Create New...