I have never used Ajax with JSON. Are there any good resources to look upon?
Think of Ajax as a way to send and receive textual content with the server. The format of the messages you send back and forth is up to you. You could use JSON, XML, YAML, CSV, or whatever else you want.
If you separate these two concerns your problem should be a lot easier to approach.
Figure out how to make an Ajax call to your server
Figure out how to parse and serialize JSON
If you use a JavaScript framework, like jQuery or Prototype, both of these things will be handled for you pretty seamlessly with their Ajax APIs.
http://api.jquery.com/jQuery.ajax/
http://www.prototypejs.org/api/ajax/request
Related
From my understanding, AJAX requires the use of the XMLHttpRequest object. What I am confused on is the source of where the XMLHttpRequest object is connected to? In the school projects, I have connected it to XML and mySQL and was told that I am doing AJAX. What if I connect the XMLHttpRequest object to a PHP script which contains an array of data? Would that count as AJAX?
The reason why I ask is because I was thinking of adding AJAX to my resume, but since this area seems so broad and I have had limited experience with it, I want to make sure I have a clear understanding of this technology.
The AJAX part is just how the request is made from the client. If it happens asynchronously using XmlHttpRequest, it doesn't matter where the request is going :-) It could be a request to an server side script in PHP, a JSON file, an xml file, or anything else.
It's not broad at all. Any time you do an async web request (actually, it doesn't even have to be async, but that's really the best way to to use it) via javascript (rather than through a Form submit) you're using AJAX. What you connect to or what you retrieve is irrelevant.
Without being rude, I'd like to point out that if you state on a resume that you possess "a clear understanding of this technology" then you're not being honest, since you're asking this question, which indicates that your understanding of the technology isn't "clear".
If, however, you're totally confortable with the use of Ajax and were simply not entirely clear on it's lexical definition... well... now you should be.
yes ,the ajax can used for all language,soever java or asp and php
Is anything that uses JavaScript and asynchronous communication of XML data considered Ajax?
Most people who deal with AJAX would consider any usage of XMLHttpRequest to be AJAX.
This doesn't mean that the request need be async either.
These days, JSON replaces XML for communications.
From wikipedia:
With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data is usually retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not needed (JSON is often used instead), and the requests need not be asynchronous.
AJAX seems to encompass any application which retrieves data using the XMLHttpRequest object. Despite it's name you don't need to use XML and I'd wager most AJAX apps these days are using JSON instead. Also they don't necessarily make asynchronous requests. We probably need a new buzzword at this point. Maybe websockets will take off!
The term AJAX and its abbreviation is a misnomer. It has nothing to do with XML. It typically refers to the XMLHttpRequest function. The name of this function again is a misnomer because you could use it to get or send JSON data, plain text, or even binary data now.
AsyncHttpRequest would have been a more appropriate term for the function, and AJAH (Asynchronous JavaScript and HTML) instead of AJAX. On a side note, although XMLHttpRequest allows synchronous requests too, they'd probably be better off getting rid of it altogether.
Typically AJAX applications make good use of asynchronous calls and avoid page refreshes as much as possible. Gmail is a good example. Facebook, on a modern browser, also uses AJAX. Clicking on different links like "News Feed", "Events", etc. doesn't cause a page reload although the path in the address bar changes. Github does the same on modern browsers.
I am getting information from the browser using Javascript / HTML5 that I want to pass back into Sinatra and Ruby.
How can I pass this information back into Sinatra so that I can use it in other parts of my code?
If you want to pass any information from the client-side (JavaScript) to the server-side (Sinatra), you need to use AJAX or something like Comet. You should serialize, encode your data, send it using XMLHttpRequest and handle in the server-side code. After that, you may return an answer to your client-side.
I have no idea about AJAX programming features. I just know that it is Asynchronous Javascript and XML.
Please help me in knowing about this language.
I have gone through many AJAX tutorials. But none of the programs are running. Why I don't know.
Do we save the file with .HTML extension?
Read:
AJAX Tutorial by W3Schools.
AJAX Programming by Google Code University
To start coding you can get the Ajax Control Toolkit by Microsoft. You should read Ajax Control Toolkit Tutorials to get a grasp of it.
You can use the free Microsoft Visual Web Developer 2010 Express Edition as your IDE.
Aside from the correct responses that the others gave you, judging from your question I think you first need to learn about client-side and server-side code.
Do we save the file with .HTML extension?
Yes and no. You will have an HTML frontend, that for instance contains a button. This will be interpreted from the client's (=user) browser. In fact it may be rendered differently depending on the browser/OS/etc.
Now, you attach some Javascript code to this button. This also runs on the client's browser, and creates a XMLHttpRequest object, either directly or through the use of a library (JQuery & Co.). Note that a library is not necessary to do an AJAX request. It will make your life easier if you do a lot of AJAX calls, but it is not essential.
And here's where the magic happens: the XMLHttpRequest object will call asynchronously (i.e.: without reloading the page) a server-side page. This may be a PHP, ASP, Perl etc etc file that does something on the server, for instance queries a database. This part of the operation is absolutely independent from the client. The user can close the browser before the server-side code finishes to load and the server will not know about it.
Once the server-side code has finished executing it returns to the client with some response data (e.g. a piece of XML, JSON, HTML or whatever you like). Finally the client executes (or not) some other Javascript code in response to this, for example to write on the screen, again with no reloading of the page, something based on what the server has returned.
Maybe I can help you understand AJAX by clarifying the concepts a bit.
Please help me in knowing about this language.
AJAX is not a language, it is a way of using existing techniques to improve the user experience of a web site. The language is Javascript in the browser but you can use any server side technique that you feel comfortable with (ASP.NET, Java, PHP, Ruby etc.)
Do we save the file with .HTML extension?
Well, that is not really the point. What you have to grasp here is that there is a server and a browser that interact with each other. Yes, you can use static HTML files for your pages (and save them as .html files), but you'll need a server to respond to the requests of the browser. This may be why your sample code is not working; you need to set up a server that works with your pages.
The whole idea behind AJAX is to improve the user experience by not reloading the entire page when a user interacts with it. You request the data you need and update the page by using Javascript to update the HTML. This is called an out-of-band or asynchronous request.
I just know that it is Asynchronous Javascript and XML.
That is what the acronym stands for but it doesn't quite cover what the technique is for, nor is it accurate any more. In the beginning XML was used to transfer data from the server to the client. People found that XML is not really that easy to work with in Javascript so now it's more common to use JSON. JSON is a snippet of javascript that can be evaluated in the browser. The snippet creates javascript object(s) that represent the data.
If you use a Javascript library, like others have suggested here, you won't have to worry about many of the details though.
Before you get into AJAX you should make sure that you understand:
HTML and CSS
Javascript
how to modify HTML with Javascript
how a browser requests information from a server
how to handle requests on the server
If you are not comfortable with all of these concepts, stick with 'regular' web pages and try to improve your knowledge step by step.
Once you get the basic knowledge from W3school, I suggest you use a framework. Usually developers do not use XMLHttpRequest at all. Instead, javascript frameworks like ExtJS, jQuery and other frameworks make your work simple. I suggest you learn bit of javascript as well. check out jQuery.
Just to add that AJAX is rarely used in its pure form with XMLHttpRequest. You will often use it as a part of AJAX UI libraries which make your life easier. If you are from the Java world - such an AJAX library is Richfaces.
Instead of worrying about how to do AJAX, use something that allows you to forget about it. Frameworks like NOLOH do AJAX (and Comet) for you automatically without you having to do a thing. Just concentrate on your application, and business logic and it does the rest.
Really, everything is done via AJAX if available, automatically. No work on your part. If you're don't want to spend much time researching it, check out this short video that was demonstrated at Confoo PHP Conference this past March http://www.youtube.com/phpframework#p/u/11/cdD9hSuq7aw.
For all those worried about, well, if it's all AJAX, what about search engines? No need to worry, http://dev.noloh.com/#/articles/Search-Engine-Friendly/.
So instead of having to worry about all these different technologies, or the client-server relationship, you can sit down, code and have your website/WebApp working in no time.
You can read about NOLOH is this month's cover story of php|architect magazine, http://www.phparch.com/magazine/2010/may/.
Enjoy.
Disclaimer: I'm a co-founder of NOLOH.
It is easy one. Ajax getting data from server side by client side execution. We have to do use XMLHttpRequest to get the result.
I'm not so familiar with Ajax but I keep hearing Json mentioned as some kind of competing option. Is there a rule for when to use one versus the other?
I'd like to process Javascript events in my app and update the front-end dynamically from the app but I'm not sure whether I need to use Ajax or Json for this.
Ajax and JSON are very different things.
From Ajax (programming):
Ajax, sometimes written as AJAX
(shorthand for asynchronous JavaScript
and XML), is a group of interrelated
web development techniques used on the
client-side to create interactive web
applications or rich Internet
applications. With Ajax, web
applications can retrieve data from
the server asynchronously in the
background without interfering with
the display and behavior of the
existing page. The use of Ajax has led
to an increase in interactive
animation on web pages and
better quality of Web services thanks
to the asynchronous mode. Data is
retrieved using the XMLHttpRequest
object. Despite the name, the use of
JavaScript and XML is not actually
required, nor do the requests need to
be asynchronous.
From Introducing JSON:
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
Here's some JSON:
{ "taco" : "awesome", "burrito": "less awesome", "fishTaco": "1000" }
Looks pretty much like an array in this case.
And you can use AJAX to get the JSON. I use it to return table data often. You've probably already used JSON-like data in your javascript but didn't realize it.
I prefer to request JSON data rather than XML or HTML. I find it easier to deal with than XML, and more flexible than HTML.
JSON is not a competing technology to AJAX it's just a data format.
Where you might hear competition is between XML and JSON, JSON having the advantage of being typically lighter and in native javascript already, XML having the advantage of portability and toolsets.
Introducing JSON
As some have stated, these are two different things entirely. AJAX is a method of using JavaScript to initiate HTTP requests to fetch data. That data can be in any sort of format, but most commonly XML, HTML, and yes, JSON.
So, as already mentioned, JSON is a data format much like XML or CSV, just with a different set of formatting rules.
Json is nothing more (and nothing less) than a format of the data you transfer with the Ajax-way of talking to the server.
Some transfer the data in the form of xml, other just plain text, others use Json.
More info about JSON on Wikipedia: http://en.wikipedia.org/wiki/Json
Ajax and JSON aren't the same thing. Ajax is a technique combining, among other things, lightweight asynchronous requests and typically some DOM manipulation, in order to create richer user interfaces in web applications.
The "X" in Ajax is often taken to mean "XML", and many sites using Ajax use XML as the format of the data returned by the server in response to such requests.
JSON (http://json.org) is a lightweight data interchange format based on Javascript's object notation. As such, it's easy to parse in Javascript. It's also a lot less verbose and repetitive than XML.
I think you may be talking about AJAX vs JSONP
http://en.wikipedia.org/wiki/Json#JSONP
If that's the case, the one benefit of using JSONP, is that you can get around the cross-site sandboxing (although, possibly introducing new security risks)
AJAX is used for get data from server, whereas JSON is just a data format which can used to send data to the server.
I thought I would provide this comparison from my class lecture
AJAX (Asynchronous JavaScript + XML) incorporates several technologies:
Standards-based presentation using XHTML and CSS;
Dynamic display and interaction using the Document Object Model (DOM);
Data interchange and manipulation using XML and XSLT;
Asynchronous data retrieval using XMLHttpRequest;
JavaScript binding everything together.
JSON, short for JavaScript Object Notation is a lightweight data interchange format. Its main application is in AJAX web application programming, where it serves as an alternative to the use of the XML format for data exchange between client and server.
The above answers are correct, but If you are new to using web technologies, all you need to know is simply
that Ajax is a subset of JavaScript.
It is a technology, a means for you to send only portion of the web page data back to the server to get processed
and get the response back while the user is interacting with other parts of the page. This way, the
Interaction with the page is consistent and seemless from the user stand point. Now, JSON on the other hand is
the how you can format the data (similar to XML) that you are sending back to the server, and getting back.
and it's used primarily with Ajax. It was developed and used mainly
because it is lightweight and human readable, which makes it more efficient and user friendly.
Hope that helps a bit.