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
Ajax - Asynchronous JavaScript And XML
What does it include? HTML, JavaScript, XML, jQuery?
What is the best way to start learning Ajax? Should I start from the basics of HTML and JavaScript or base my instruction on a particular language or library?
Ajax is, in short, the process of communicating with a webserver from a page, using JavaScript, without leaving the page.
The key things you need to know for this are:
The JavaScript needed to make the request and handle the response
The server side code needed to receive the request and make the response (unless you are using a service that provides this for you)
The server side of this depends very much on what server side environment you are working with, so there is little useful that is specific that could be said. What can be usually said are what form the responses can take.
JSON is a popular approach for sending structured data.
XML is another way to send structured data, but has been falling out of favour of late since JSON is, arguably, easier to work with.
Chunks of HTML are popular for shoving into pages with innerHTML.
Tiny bits of plain text are useful for simple responses.
As for the client side, there are three common approaches:
XMLHttpRequest: Well supported and flexible.
fetch: A replacement for XHR with a nicer API but more limited browser support.
JSONP: A hack to work around the Same Origin Policy rendered obsolete by the introduction of CORS but which you might stumble across from time to time.
I mentioned the Same Origin Policy above. Normally a script isn't allowed to read data from another domain for security reasons. The CORS standard allows you to work around this.
Now for some resources:
The W3C provides a good guide to JavaScript and other web standards if you need some background.
MDN also has an introduction to JS
MSN has a good guide to the XMLHttpRequest object
Ajaxian has an introduction to JSON-P
jQuery has functions to help with Ajax.
You Need to have knowledge of HTML and Javascript. W3Schools has a Tutorial on Basics which will help You learn. The best way to learn is to put some code and use it. And Moreover now, JQuery ( a javascript library ) , makes learning Ajax more fun and easier. The Website has good documentation and some Sample Ajax code too.
AJAX = Asynchronous JavaScript and XML.
So basically it is javascript. jQuery among other things simplifies your code sending AJAX requests. HTML is markup, not language and is not related to AJAX.
You may start with this tutorial.
You need first to understand Javascript and how to program it.
On my side, when I first started to develop Javascript, my experience was mainly C, C++, Perl and the like.
Due to that background, it quickly occur to me the need in Javascript to be able to query data from the current page (without any redirection) to the web server dynamically. I then discovered the usual key Ajax object XMLHttpRequest.
I would recommend you to use the "regular" Javascript at first, perform some basic dynamic actions, like time display, moving text (...).
Then you could try to implement a simple program that display the clock value from your server. Because XmlHttpRequest perform a dialog between the web server and the client (browser).
For that you need to have access to a web server (eg Apache).
You need to chose what language you will use server side to answer the Xmlhttprequests, e.g. PHP, Perl CGI, etc...
You need to have Apache dispatch the page requests to that PHP ... script.
The script will have to output the result.
Browser-Javascript request
==> Web server (eg PHP)
to Display the clock =
"
Back to browser <==
The the javacript code will get that answer and will have to display that result somewhere.
In terms of Book, Javascript 5 by Flanagan is my first choice.
By actually using it. Is the best way of learning something. ANY thing!
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 1 year ago.
Improve this question
Good night guys!
I'm new to programming and now I'm studying the $ .post () method and I have a few questions:
1 ° - Why should I use the $ .post () method?
2 ° - In all the examples I see, they always use the $ .post () method to send something to PHP ... Is it possible to send something other than PHP? If so, could you give me examples using only JQUERY, HTML, mysql and JSON? (that I'm studying)
Note: I'm a beginner.
$.post() is a jQuery method that allows you to send a request to a server (typically) with data that can be processed by the server and sent back.
PHP is a programming language that can run in a server, accept the $.post() request, and process the request.
$.post(), the jQuery method, is used in the "front-end" of web apps. The front-end is the part the user uses. So, a typical example of the use of a $.post() request would be a user on a social media app adding new images to their profile. The image is transformed into data (bytes) and sent from the users computer to the server with the $.post() method.
That's where PHP comes in. PHP will receive the data bytes and save it to the users profile. All the magic of making sure we have the right user and pulling up their info then adding the new image to their profile actually happens here. At the end of it, typically a "success" or "error" response is sent. For reference, when you get a 404 error or a 500 error, that is where the error came from. A server.
The front-end of web applications is very limited. It only has JavaScript, jQuery (which is just a sub-set of JavaScript), HTML5, CSS3, and some altered versions of these.
The back end, the server that handles all the requests and sends all the data back, can be done in a plethora of different languages. PHP is an older language but it is still actively updated and still used in a lot of legacy apps. We now have Node.js, Java, Python, etc. A lot of different languages to write a back end.
Hopefully this clears some things up for you. Please feel free to ask me questions in the comment section or send me a message if you don't have enough reputation to comment yet (don't know the numbers lol).
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
instead of doing all your server operations via the POST method token ( and the content type set to json ).
I've done some research here and I am referring to the method tokens mentioned in the ietf document.
https://www.rfc-editor.org/rfc/rfc2616#section-5.1.1
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
I don't see the benefit of using all the other server type requests. I know they are used, particularly what spurned this interest was Backbone's use as seen here:
var methodMap = {
'create': 'POST',
'update': 'PUT',
'patch': 'PATCH',
'delete': 'DELETE',
'read': 'GET'
};
These properties are eventually passed to the xhr open method which you can read about in the links I posted above.
Actually the MDN article has pretty much no information while the W3 articles seems a bit esoteric.
What you've described is an application design philosophy called Representational State Transfer (REST). The philosophy is much more encompassing than just using multiple request methods. It also covers the idea that each type of data needs its own URL, how that URL should be logically structured and what should belong to query parameters and what should be a URL path. REST is one of the earliest ideas related to Semantic Web - the idea that websites should be easily readable to machines as it is to humans (or to put it another way, the idea that the website should be easily understandable to developers as it is to regular users).
You can read the original paper describing REST here: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
REST is actually just one chapter in the whole paper. The paper describes what a web architecture should ideally look like.
Do you need REST?
The short answer is of course no. Technically speaking you're allowed to do whatever you want that works. Indeed, back when ideas of REST was first introduced there were no easy way to do PUT and DELETE requests on some browsers. So people stuck to GET and POST and the HTTP spec was updated specifically to make GET and POST have RESTful meaning.
The HTTP specification recommends that GET only be used for indempotent operations (requests with no side effect) while POST should be used whenever a request causes something to change in the server. But developers have been using GET to update databases due to easy debugging because you can just construct the query in the URL entry field in your browser. The RESTful way is to only allow POST requests to update the database (or save anything to file).
What's the advantage?
The advantage is to essentially allow developers to treat the web as an API. Allowing machines to read webpages allows for things like mashups, creating mobile apps as front-ends etc.
A good API or library is consistent. A consistent API is easier to use, easier to remember and doesn't require the developer to look-up documentation too often. REST attempts to provide this consistency by giving real meaning to the types of request. Therefore if you see PUT request you don't have to guess what it's doing.
As such, as a programmer, it is to your advantage to not only be RESTful as much as possible but also convince as many other programmers as possible to create RESTful websites. If all websites are RESTful, writing scripts to do smart things with online data becomes much easier.
On the other hand, as a programmer, you also have the freedom to disagree with other people's ideas.
I have heard about AJAX for years but I never felt the need or the intrest on learning it, I knew it was a mix of Javascript and XML but I never took the time to actully try to understand it, until now.
This is what I currently understand about AJAX. Ajax is not a language, it is just a combination of existing technologies, basically JavaScript and XML (and possibly HTML and CSS) and uses the XMLHttpRequest to comunicate with the server in the background to update/load only parts of a page instead of reloading the whole page.
Things I don't fully understand.
1- Is there any AJAX documentation or API that I can refer to to see what functions/options AJAX offers?
2- Why every book in Amazon seem to be old? Is this because AJAX this is not a language and doesn't change?
3- I read the tutorial at www.w3schools.com and I was wondering if what is shown in this tutorial is basically all AJAX can do, basically, Request and respoind to a server?
Again, all I'm trying to understand here is basically how much of a learning I still need to go through in order to have a better understanding about AJAX.
Thanks a lot
Long story short: AJAX lets you make calls to the server without submitting a form or navigating the page. That is all it does.
Originally it stood for "Asynchronous Javascript And XML" because the XMLHttpRequest object was designed to receive updates in XML format. Microsoft added the object so that the Outlook Web interface could pop up new mail alerts by polling the server.
Since then, most programmers have eschewed the use of XML as the data exchange protocol and rely on JSON instead. JSON is far easier to parse and work with.
While I could go through some examples of the low level XMLHttpRequest interactions, other sources have that well covered.
Instead, I'm going to give you a bit of advice. Study Javascript and consider learning the jQuery API. JQuery forces functional programming and makes common activities like AJAX calls super-simple to accomplish. You'll learn to be a better Javascript programmer because of it and will hopefully learn to make your sites more interactive thanks to the power that background server requests bring to the table.
Although the 'X' in AJAX stands for XML, applications today are more likely to use JSON encoding over XML as the return data can be evaluated directly by the browsers JavaScript interpreter. The core enabling JavaScript object is XMLHttpRequest which was originally developed as an ActiveX component for IE 5. It has since become a standard object in all web browser implementations. You can read about the core functionality here: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest.
Your best bet would be to research modern JavaScript frameworks such as jQuery. http://www.jquery.com/ for information on how to use AJAX technology within your web applications.
This is a bit of a vague question, and likely to get some down votes, but I think it's specific enough that it does warrant some information.
In a nutshell, AJAX is a why for JavaScript to request information asynchronously. The XML portion is a bit of a misnomer, since you don't have to explicitly deal with XML at all. Frequently, you'll use AJAX requests to read in JSON information (since it's so easy to parse and use).
AJAX isn't really a language, or even a framework. It's a technique. It is made possible by the XMLHttpRequest class, along with some related technologies. Since it isn't 100% consistent across all browsers, it is usually best to use a third-party library. jQuery and most other larger frameworks usually have it built in. You can also find some small AJAX-only libraries, like this XMLHttpRequest project on Github.
Every book on the technique is probably old because nothing has really changed substantially since the technique starting becoming popular. I've been using it for at least the past 3-5 years, and not much has changed (other than a bit more standardization in modern browsers).
The respond and request is basically all AJAX can do. However, that enables a whole world of possibilities. Long story short, it's a way to communicate with the server without having to refresh the page, allowing for much smoother UI and UX.
The simplest way to think about it is that it lets you fetch data without a page reload.
Think about how Google Maps loads in bits of the map as you drag around - it clearly doesn't load the map for the whole world.
In older map sites you clicked a left, right, up or down arrow, the page reloaded and the new data was shown.
AJAX lets you make pages feel much faster and smoother.
Technically JSON is usually used instead of XML as it's more Javascripty than XML.
Most sites likely use it somewhere or other, ranging from loading sidebar widgets after the main content, to the whole app, like Gmail.
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 9 years ago.
Improve this question
There are a lots of new frameworks, technologies coming up. And it's becoming so hard to follow up all of them. One of the thing that confuses me is client side frameworks. I heard that Angularjs,Backbone,Knockout,jsviews,knockback, SPA... are the most popular right now.But I can't understand how does the security concept applies? If we take an example of querying a table form database it's now possible to make queries from client side database, by specifying table name and fields and etc... So if it works that way, than everyone else can write another query and get all other information. I am pretty sure that I am missing something very important here, and it doesn't click my mind. So please can anybody explain me where can I start learning those primitives.
I really appreciate, and I am really eager to learn but I am searching it wrong way I guess.
Whatever the framework used, the security matter will still the same, and very similar to mobile apps:
which data can you afford to be handled in an untrusted environnement
which treatment can be applied in an untrusted environnement
By "untrusted environnement" I mean the browser itself. You have to understand that any code executed in the browser can be corrupted by a medium/good JS developper.
Data security suffer the same threat: giving access to data from your client means that you do not control anymore who is using it.
Once you've dealt with this simple matter, it became easier to decide what must stay on server side, and what can be deported to client.
That said, there are various ways to make data/algorithm steal more difficult:
Obfuscation that comes with minification
Double data validation (forms for example): both client and server side
Authentication protocols, like OAuth
Binary over webSockets, instead of plain json and ajax call...
The browser sandbox imposes some limitations, but mainly to protect the local computer from damages due to malicious JS code. It does not protect your code nor your data from being seen and manipulated by the user itself.
I am using angular for some of my projects. I haven't used other frameworks , but in angular you usually consume an API to get the data. You don't query your database directly. So, the responsability of securing your data is more in you API (Backend) than in your angular client.
You can use OAUTH, or other security method that you want to make your api safe.
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 am into implementing a pull communication between my javascript client and python server. I have wasted my last two weeks struggling with websockets and socketing, but now I decided to give it up.
I am looking for the most convenient way to implement python-javascript communication where the client sends requests to the server, to which the server can answer. I have seen lots of ways, some of which:
ajax
json
socket, etc
I would love to hear your opinion on the advantages of the different possibilities. ( If you also have some great tutorials which I can use to get started, I would really appreciate them. )
It seems you are a little bit confused on definitions and technologies, so let me start of by clarifying some defitintions (rough descriptions, not exact):
JSON: A format to pack data structures (like arrays) into a string and to retrieve the data. It is one the most used formats to submit actual data but is by itself not capable of transmitting data: It is only the data itself
AJAX: The dominant technology for sending requests to a server without reloading the complete page. AJAX works through the HTTP protocol and sends the same headers as would be sent if you would send the same request by visiting the page (Exception: Headers that are special to AJAX, depends on library etc.). By itself AJAX is the technology to submit the data but is not the data itself. However, it can, for example, submit form data encoded in the usual URL encoding. But it can also send JSON data
Sockets: The definition of a socket is very broad and general. Normally, it describes a low layer like TCP (below HTTP in hierarchy) but since you are describing JS + Python I would assume you mean browser - client communication. In that case there is WebSocket. I have not worked with that technology yet but from what I hear it allows arbitrary connections etc. For a normal use case way to advanced.
These are the technologies you mention. Additionally, I would like to mention two more:
XML: Like JSON, but a different format. XML has various advantages and disadvantages. From my point of view the biggest advantage is that it more flexible and on complex structures easier to understand than JSON. But this flexibility comes with the disadvantage that it is harder to learn.
JSONP: Similar to AJAX in that it is used for communication but as the name states, it submits JSON data (I think...). Has the advantage of allowing cross-domain requests (also advanced stuff).
Since your question is not that precise, I will answer it (like assumed above) in the Web context: JavaScript is run from the browser and the server is a web application written in Python.
For this I would recommend a combination of JSON & AJAX: JSON is natively available in both JavaScript and Python and libraries like jQuery offer easy interfaces to data recieved via JSON. I recommend AJAX for the same reason: It's easy to use, integrated in most JavaScript libraries and needs no work on the server side whatsoever: For the server there is just a request to handle.
Example on the server side:
# Request comes in:
data = json.loads(request_body)
# Do calculations
output = json.dumps(out_data)
send_response(output)
On the client side, you could plain JavaScript or jQuery for sending the request and handling the response.