Using Javascript to get content from another website - javascript

I have a plugin that puts all the content in a database, so I cannot put PHP code into the plugin, it won't execute. It does allow Javascript though.
So how would I go about using javascript to contact a page and get the data, if I have the data just pass the content, like this:
field1=data|field2=data|field3=data|field4=data
like that string.
Is there a way to get that content using javascript or jquery, so that I could parse that and pull the data I need?
I can build a php script to output that data, since I cannot have PHP executed in the plugin, so I could still securely get the data I need, since I could pull the data and make sure to pass a key, so it is secure.

Related

Getting data from another website which is using AJAX to change content

Is there any way how to get data from another website which is using AJAX to change its content? For now, I am using PHP Simple HTML DOM Parser, but I can't use it in this case. I want to simulate just one click. And after this click, I get new data which I want to parse.
If the website has RSS feeds. Try using that instead. http://website.com/rss.xml or whatever the rss url is. Then you can use Simplepie, or any other RSS Feed parser to get the data.

How to do a MySQL query with AJAX without revealing db user password?

I'm new to JavaScript and AJAX. My experience is mostly in PHP. How can you do a MySQL query from JavaScript without revealing in the View HTML Source of the web browser the connection information for the MySQL database such as the db user's password? Thanks!
You make your JavaScript request the information from a PHP script, which checks the user's login cookie (like any other page would) and queries MySQL, returning the information to the JavaScript in whatever form it needs (JSON, usually).
In this case you don't perform the actual database query from the JavaScript code. The fact that it's using AJAX doesn't move database connectivity to the client, it just allows you to request information from the server without refreshing the page (as well as potentially moving some of the UI logic to the client).
Your AJAX call would simply make a request to a PHP file in your website which could:
Render part of a page, where the JavaScript code from the other page which called it would insert that markup into the open page. Or;
Render data, usually in JSON format, which the JavaScript code from the other page would read and use.
So let's say you have PageA.php which has a bunch of HTML and JavaScript. You want some of that JavaScript to make an AJAX call to the server to get data. You'd create a PageB.php which behaves just like any other PHP code, but instead of using HTML between the PHP code fragments (or in echo statements) it would use JSON syntax to represent the data being returned.
The JavaScript code on PageA.php would make an AJAX call to PageB.php, read the data that's returned, and use it in the HTML of PageA.php entirely client-side without having to refresh PageA.php.

Javascript or jQuery method to parse ASP.NET MVC Route URL

I'm building an ASP.NET MVC 4 website that needs to be available offline (HTML 5 manifests/caching), so I will be unable to take advantage of server side HTML generation.
Right now, I just have generic/cacheable HTML on the View (.cshtml) and I'm making jQuery AJAX calls on document ready to load the data from the server and using mustache.js to generate the HTML.
Being constrained to doing HTML generation only in the client side, I'm unable to use Url.RouteUrl to generate links and also constrained to having to parse the current URL manually when navigating to a details page, and using the Id (or whatever the parameter is) to make the AJAX call to retrieve the information for the specific record that I need.
Since I'm still using MVC URL Routing (and would like to keep using it) to return the corresponding View (as in, http://localhost:27954/Route/Test2/7?mytext=hellow), I'll need a javascript or jQuery function to both be able to parse URL's and retrieve the value for a given querystring parameter, and ideally another method to generate URLs.
Since I'm obviously not the first person in this situation, I was wondering if anyone had any proven methods already that they could share, or any recommendations.
Thanks!

parse external json source to html

I need to get some data from a json file stored at another server than my own. I've received the url of the file but have to "anonymize" it below, the url is exactly as below but with a different domain.
http://api.somedomain.com/v1/26963723e61eae69cefd/companies/5565592010/related-articles.json?languages=nor&per_page=10&page=2
Now I want to render the data in that file into a list or table structure in my html file, preferably after the page has loaded. If jQuery can be used for this then that would be great otherwise regular javascript will do.
Unless someone can toss up a solution I'd be happy to take pointers on where to turn to learn about how this can be done.

Load mysql's value into javascript

i have stored values in mysql and i want to retrive that value in webpage
but the webpage is creted only using javascript
so how can i use that database's value in javascript
You need to have a server side script in the middle so you can retrieve the value using ajax.
What you're asking for is only possible with a restful nosql database like CouchDB.
You really need to give more information as to what you want to do, but as you implied that the page isn't dynamic the method would be to use ajax to request a dynamic page (written in a sever side langugage) that retrieves the data from the database and outputs it in the required format.
You'll need to either...
a) Have a separate, server-side script which can run the appropriate query, and then pass through the data to the page through an AJAX-type call (jQuery et cetera have functions to simplify the AJAX side of things, if you so desire),
OR
b) Put some server-side code into the page that is evaluated before the page is served and writes the data into the page within something that the Javascript can access it from (i.e. the definition of a variable or some such).

Categories