show message on success ajax [closed] - ajax

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
On the success function of jquery ajax request, i have to show a div, can anyone suggest a way to do this
dataString = "labid="+val;
jQuery.ajax({
type: "POST",
url: "../pim/manageLabelsAdmin",
cache: false,
data: dataString,
dataType: "json",
success: function(data) {
if(data.success == "yes"){
//alert(data.status);
} else {
alert("Occured internal Error. please check network connection");
}
}
});

If the message to show is in the DOM already, but hidden, you could do something like this in your success callback:
if(data.success == "yes")
{
$("#id-of-message-element").show();
}
Otherwise you could add the message to the DOM using any of .append() or .prepend() or .html() or .text() depending on your needs.
More on the DOM insertion methods here:
http://api.jquery.com/category/manipulation/dom-insertion-inside/

if your div has id then this
$('#yourDivId').show();
else if your fiv has class
$('.yourDivClassName').show();

Related

How does POST and PUT works? [duplicate]

This question already has answers here:
What is the difference between POST and GET? [duplicate]
(7 answers)
Closed 9 years ago.
I know that there are four request types such as get ,put ,post ,delete .When and why will I use type='put' or type="post" ?Basically what are the differences between them?
$.ajax({
url: '<?php echo site_url('rest_api / contacts ')."?format=json"; ?>',
type: "put",
data: $('#subpanel-contacts-add-form').serialize(),
success: function (response) {
//some tasks
}
error: function () {
$("#subpanel-contacts-form-result").html('<div class="alert alert-error">Error: There was an error while submitting!</div>');
}
});
PUT and GET are the protocols to exchange data between the server and UI define by the standard committee.
Type attribute in the $.ajax function in the way to tell the engine that what kind of request is being
generated and accordingly it is handled on the server side.
Refer to the link posted below for more explanation and difference between the protocols.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

MVC + controller view not displaying [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using ajax for posting 2 values to my controller, the controller got the values but wouldn't display the view. Please assist what I am doing wrong here. Thanks.
Javascript:
function grantPermission() {
window.FB.login(function (response) {
if (response.authResponse) {
uid = response.authResponse.userID;
accesstoken = response.authResponse.accessToken;
var postData = { facebookUID: uid, facebookAccessTok: accesstoken };
$.ajax({
url: '#Url.Action("SavePhoto")',
data: postData,
dataType: 'json',
success: function (response) {
// process the results from the controller action
// window.location.href = response.Url;
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
alert('User cancelled login');
}
}, { scope: 'publish_stream' });
};
Button:
<input type="button" id="auth-loginlink" value="Proceed" onclick="grantPermission();"/>
Controller:
public PartialViewResult SavePhoto(string facebookUID, string facebookAccessTok)
{
return PartialView("BlurredPhoto");
}
You need to embed the returned HTML back into your document somewhere. e.g. If you add a
<div id='MyDiv'>
then change your ajax call to
success: function (responseText, textStatus, XMLHttpRequest) {
$("#MyDiv").html(responseText);
}
As Slaks has mentioned, you also need to change your return datatype accepts to 'html'.
You need to do something with the HTML source from the server in your success callback.
You should probably start by not telling jQuery that the HTML is datatype: 'json'.

ajax not working in breezing forms component of joomla [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
function ff_chk_username_unique(element, action)
{
alert(element.value);
alert(action);
var actiona="http://localhost/myproject/check/check_username.php";
var form_data = {
username: element.value,
};
alert(actiona);
$.ajax({
type: "GET",
url: actiona,
data: form_data,
success: function(response)
{
alert(response)
}
});
} // ff_chk_username_unique
code of my ajax file...
file is not called within ajax,
is ajax defined properly?? please help me solve it....
it's working in breezingforms but you need to add jquery file when you use ajax...

MVC3 Controller returning JsonFile [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I am having a problem with a json result. When calling from the jquery it is returning a file to be saved instead of executing the success function. The get jquery request occurs in the document.ready function.
Any help would be appreciated.
public ActionResult Locations()
{
LocationsModel lm = new LocationsModel();
return Json(lm.getPins(), JsonRequestBehavior.AllowGet);
}
I have also tried:
public JsonResult Locations()
{
LocationsModel lm = new LocationsModel();
return Json(lm.getPins(), JsonRequestBehavior.AllowGet);
}
The jquery is as follows:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: this.href,
data: "{}",
dataType: "json",
success: function (msg) { getPins_success(msg); },
error: OnError
});
Thanks,
Chris
Edit:
Never mind it was a duh. Once I moved the json request to another action in the controller and loaded the view it all worked out. Now I am having parsing problems but that is another issue all together.
you should use getJson instead.
For you it would be:
$.getJSON(this.href, function (msg) { getPins_success(msg); });
This will let you parse the return data as json.

Jquery Autocomplete not showing results [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I have the following code:
var acOptions = {
source:function (request, response) {
$.ajax({
url: "index.php?option=com_fmw&view=keywords_api&controller=keywords_api&format=raw",
type: "GET", dataType: "json",
data: { expr: request.term},
sucess: function (data) {
response($.map(data, function (item) {
return item.value;
}))
}
})
},
minChars: 1,
dataType: 'json'
};
$( "#search_box_input" ).autocomplete(acOptions);
I get the following response from the server:
[{"value":"Greater"},{"value":"great"},{"value":"greatly"},{"value":"Greater-Axe"}]
However, the autocomplete field is not showing results, even though I can see that the ajax request got sent and that the server answered. What am I doing wrong?
sucess is spelt wrong. Try success instead.
success: function (data) {
response($.map(data, function (item) {
return item.value;
}))
}

Resources