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 8 years ago.
Improve this question
I am trying to understand what medium to use to fetch data from a MySQL database using PHP.
What is better "speed" wise, jQUERY or PHP to fetch data form MySQL on page load?
With jQuery alone you can't fetch data from mysql.
If your question is to load with the page or get the data from php after loading, I can say, that loading with page is better, because the text is standing on the page when you load it and jquery will have a delay to display the data.
$.ajax({url: 'ajax.php', success: function(data){$('#name').text(data.name)}});
When you use jQuery, you ask PHP (or other technology as .NET, ...) to fetch the data from MySQL.
In terms of usability... it depends. Perhaps you want to load your web/application schema and after that use jQuery to load the information (so the web seems to load faster). But, as I said, you will use PHP. The difference is that you can have a PHP file to build the schema and another PHP to retrieve the information.
Related
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 working with PHP and I want to scrape some data from any website. But I have a problem. I scrape data but these items number are 48. But I know that page has 11K items. Rest of datas extend when you scroll and you get new bunch of datas (48 items).
I'm scraping with simple_html_dom. How can I manipulate scroll and get data ?
Thanks! :)
Sounds like the missing data is loaded via ajax.
Check the Network tab in the Developer Console (by pressing F12). Take a look at the URL which is being called (and the response), and edit it to your needs. Then call this URL instead of the one you are taking now.
It is impossible by this way.
But if you need to scrap this data you can send requests to endpoints which return lazily loaded data. You must research js code of target site.
p.s.
If you want to use really hard approach, you can research browser emulating.
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 7 years ago.
Improve this question
The title says it all. Please give me some way for how to scrape AJAX loaded Division.
There is one website which has Product Grid Division. I want this division for scrap the data from it but the problem is when i get the page content data in another html page there is no product grid because it's loaded via AJAX after some time. For Scrapping i tried both Perl and CURL with PHP.
Thanks in advance.
From WWW::Mechanize::FAQ
Which modules work like Mechanize and have JavaScript support?
In no particular order: Gtk2::WebKit::Mechanize, Win32::IE::Mechanize,
WWW::Mechanize::Firefox, WWW::Scripter, WWW::Selenium
Also see: How do you scrape AJAX pages?
Using Selenium, e.g. through Selenium::Remote::Driver, you will be operating real browsers to access the site. Sites can be quite sensitive to subtle differences in browser behavior.
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 9 years ago.
Improve this question
I have a PHP page that retrieves a list from the DB, and I want to display it on a loaded page using Ajax.
Should I format it on the PHP side (HTML formatting), and just retrieve the data, or pass it to JS like dataA:dataB:dataC and format it client-side?
there won't be a lot of people using it, but I would like to know which is better (if there is a better method without taking the amount of users into account)
Both will work fine. However in my opinion if you're gonna use ajax - and transfer information - a better practice will be to wrap the data in JSON format and parse it on the client's machine.
Example of the php output:
{
"row1":{"field1":"value11", "field2":"value12"}
"row2":{"field2":"value21", "field2":"value22"}
...
}
Exmaple of parsing:
$.ajax(...).done(function(result){
$.each(result, function(index,value){
$('#conatiner').append('<div>'+index+': field1='+value.field1+', field2='+value.field2+'</div>')
})
});
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 8 years ago.
Improve this question
what way should I structure my files when doing Jquery AJAX requests in PHP.
i.e.
showRecords.htm - contains jQuery/AJAX that gets data (HTML) from the php file below.
showRecords.php - contains php that does some processing, likely to get data from DB and echo some HTML.
or
one file:
showRecords.php - contains the JQuery/AJAX and is the php file and requests data from itself.
also you clever people out there, please note I am a beginner in JQuery
and AJAX so please forgive me if its a silly question or trivial.
Obviously not: one file.
I'd do it this way:
showRecords.php - form processing, db requests
templates/showSomeHtml.php - displays everything that your users can see
showRecords.js - jQuery/AJAX that gets data
And if the jQuery/Ajax modifies the HTML, you could also move that (the dynamic HTML) into the templates (read about javascript templates)
I think it's up to you. If you have a quick ajax call you'd like to do and you know it won't be used anywhere but there then I see no issue with having everything in one file. On the other hand, you might need to access that processing script in multiple locations on your site. If that's the case, it's not ideal to place it all in one file. I think two files avoids confusion. Keeps everything separate and neat.
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 9 years ago.
Improve this question
Personally I would do this with PHP but maybe someone has an pro/contra for doing this with JavaScript:
I (will) fetch a few song details (about ten per page load) from Soundcloud
afterwards the statistic (played this week/total, liked this week/total etc.) will be displayed in a table
That's it - nothing special.
I can solve it like this:
let PHP do the stuff and render the whole page at once
This will of course take some time before the page is rendered.
Is there any advantage of doing this with JavaScript? I can only think of:
the page renders faster (with the disadvantage that the results may not be displayed instantly)
I'd say that doing it via JavaScript will actually take longer, as you'll have to connect again. Although, it may give an illusion of "being faster" (though I doubt it'll be noticeable).
I suppose it might depend on your usage cases too.
How are you handling authentication with SoundCloud?
I would honestly go the jQuery route.
Use a $.post() call, and within your success statement, loop through the json and append it to a table. This way, you can do something like pagination, which can update your table without needing to refresh the page.
Do it serverside and pre-load the page. The soundcloud API should not be the bottleneck here so reducing a request or two is worth it.