The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

61.Define JSON?

JSON is JavaScript Object Notation.

62.What type of response we can get in Ajax Response?

  • text data
  • html data
  • JSON data
  • XML data

63.Describe how to handle concurrent AJAX requests?

JavaScipt Closures can be used for handling concurrent requests.

64.How do you know that an AJAX request has completed?

If readyState's value is 4 means its completed.

65.How to Abort ajax requests using jQuery?

See Example Below:
var ajaxRequest = $.ajax({
type: "POST",
url: "/ajax",
data: "name1=value1&name2=value2",
success: function(msg){
//here success comes
}
});
//Abort the ajax request
ajaxRequest.abort()
When you abort the ajax call, you can see ajax request as aborted in browser console.

66.How to redirect a page after success of Ajax call?

You can use window.location.href, to redirect.
See Example Below:
$.ajax({
type: "POST",
url: "/ajax",
data: "name1=value1&name2=value2",
success: function(msg){
if(msg.success){
window.location.href='/newpage.php';
}
//here success comes
}
});

67.How do I test an empty object?

You can use jQuery isEmptyObject().
See Example Below:
var myArray=new Array();
console.log($.isEmptyObject(myArray));//return true
var myArray=new Array('This is message');
console.log($.isEmptyObject(myArray));//return false

68.How to submit a form in Ajax?

We can use jQuery ajax function to submit a Form.
See Example Below:
Following is Javascript function
function onSubmitFunction(){
$.ajax({
type: "POST",
url: "/ajax",
data: $('#mytestForm').serialize(),
success: function(msg){
if(msg.success){
//here success comes
}
}
});
return false;
}
Following is HTML Code <form id="mytestForm" onsubmit="return onSubmitFunction()"> Name: <input name="name" type="text" /><input name="submit" type="submit" value="Submit" />

69.How to get the value of textarea?

You can use val function of jQuery to get the text of textarea.
See Below:
console.log($('textarea#idOfTextArea').val());

70.How to send AJAX call without jQuery?

For sending ajax call in IE7+, Firefox, Chrome, Opera, Safari
XMLHttpRequest
For sending ajax call in IE
use ActiveXObject
See Example Below:
function callAjax(url,method) {
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
//console.log(xmlhttp.responseText);
}
}
}
xmlhttp.open(method, url, true);
xmlhttp.send();
}
callAjax('/ajax?data=1','GET')

71.How to make all ajax call cache Free?

$.ajaxSetup ({
// Disable the caching of AJAX responses for all Ajax
cache: false
});

72.How to download file?

very simple
window.location="/folder/file.pdf"

73.How can I add a custom HTTP header in Ajax?

Just Use the header parameter to set the custom header
$.ajax({
url: '/ajax',
headers: { 'x-my-custom-header': 'I am good' }
});

74.?

75.?

76.?

77.?

78.?

79.?

80.?

« Previous | 0 | 1 | 2 | 3 | 4 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com