سؤال

i was reading an article on Query Ajax and REST HTTP Basic and here i got this http://blog.rassemblr.com/2011/05/jquery-ajax-and-rest-http-basic-authentication-done-deal/

just see the code

$.ajax( {
url : '/model/user.json',
dataType : 'json',
beforeSend : function(xhr) {
var bytes = Crypto.charenc.Binary.stringToBytes(username + ":" + password);
var base64 = Crypto.util.bytesToBase64(bytes);
xhr.setRequestHeader("Authorization", "Basic " + base64);
},
error : function(xhr, ajaxOptions, thrownError) {
reset();
onError('Invalid username or password. Please try again.');
$('#loginform #user_login').focus();
},
success : function(model) {
cookies();
...
}
});

i just do not understand what kind of file type is user.json. please anyone who is familiar with .json file type then please tell me what kind of file type it is. thanks

هل كانت مفيدة؟

المحلول

Its not a file in this case. It is RESTful URL, .json part just asks server to return results in JSON format. Probably you can use /model/user.xml to get response in XML format. Twitter and many other services does this the same way.

Another common way to request specific response format is by providing HTTP Accept header.

For further reading I recommend this resource: http://blog.2partsmagic.com/restful-uri-design

Some applications return different data if the user adds a different extension. e.g. they may ask for contacts.xml or contacts.json. But different URIs imply different resources. Are the two data formats really two different resources? Or just two different representations of the same resource.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top