This displays a confirmation message, but when I hit yes, it gives this error:
HTTP Status 415 -
description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
{
xtype: 'button',
id: 'passwordRecoveryButton',
text: 'Reset Password',
style: 'border-color: red',
listeners: {
click: function(button, event){
var form = Ext.getCmp('gmiUserDetailsPanel').getForm();
var currentRecord = form.getRecord();
var emailId = currentRecord.get('emailId');
Ext.Msg.show({
title:'Password Recovery',
msg: 'Are you sure you want to send a password recovery email to ' + emailId +'?',
buttons: Ext.Msg.YESNO,
icon: Ext.Msg.QUESTION,
fn: function(btn) {
if (btn === 'yes') {
Ext.Ajax.request({
url: 'admin/passwordRecovery.htm',
jsonData : emailId,
method: 'POST',
success: function(response){
Ext.Msg.show({
msg: 'Email successfully sent to ' + emailId +'.',
})
},
failure: function(response){
Ext.Msg.show({
modal : true,
title : 'Unable to send email!',
msg : 'Unable to send email to : '+emailId+', please contact support team.',
icon : Ext.Msg.ERROR,
buttons: Ext.Msg.OK
});
}
});
}
}
});
}
}
},
},
I am attempting to pass the information of the current record (or just the email) and this is in the java controller:
#RequestMapping(value = "/passwordRecovery", method = RequestMethod.POST)
#Secured("ADMIN")
public
#ResponseBody
UserOperationResponse PasswordRecoveryEmail(Model model, HttpServletRequest request, #RequestBody UserOperationRequest userOperationRequest) throws UnsupportedEncodingException, MessagingException {
UserOperationResponse userOperationResponse = new UserOperationResponse();
[...]
Related
i have implement the validation errors message with ajax successfully, but when the previous input form is true, the previous error in that input form is not hiding. Anyone can help me to hide the previous error if input form is true?
This is my javascript code :
$.ajax({
url: `${window.url}/income`,
type: "POST",
data: {
_token: CSRF_TOKEN,
detail: arrValues,
data_contact_id,
total,
description,
invoice,
transaction_date,
to_account_id,
},
dataType: "JSON",
success: function (response) {
console.log(response);
if (response.status) {
Swal.fire({
icon: "success",
type: "success",
title: response.message,
showConfirmButton: true,
}).then((result) => {
window.location.href = `${window.url}/income`;
});
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
let fields = [
"data_contact_id",
"invoice",
"transaction_date",
"to_account_id",
"description",
];
fields.map((field) => {
$(`#${field}`).removeClass("is-invalid");
$(`.${field}-error`).html(``);
});
let errors = jqXHR.responseJSON.errors;
$.each(errors, function (key, value) {
$(`#${key}`).addClass("is-invalid");
$(`.${key}-error`).append(`
<span class="text-danger" style="font-size: 0.8rem">
${value.map((v) => "<strong>" + v + "</strong><br>")}
</span>
`);
console.log("Field : ", key);
});
Swal.fire({
icon: "error",
type: "error",
title: "Error!",
showConfirmButton: true,
});
},
});
In my controller i have return validation error json from Validator::make()
if ($validator->fails()) {
return response()->json(['errors' => $validator->errors()->all()]);
}
$.ajax({
beforeSend: function(){
$(".key_of_form").removeClass("is-invalid");
$(".error_of_key").empty();
},
complete: function(){
// Handle the complete event
}
error : function(){
// Handle the error event
}
// ......
});
$(`#${key}`) add class key_of_form
$(`.${key}-error`) add class error_of_key
before submit of form or beforeSend of ajax you need reset error messages same as :
$(".key_of_form").removeClass("is-invalid");
$(".error_of_key").empty();
I am developing asp.net core project. Can I Display ViewBag value in sweealert?
Swal.fire({
title: "Successfully Added!",
text: "#ViewBag.OrderNo",
type: "success",
confirmButtonClass: 'btn btn-primary',
buttonsStyling: false,
....
})
Edit
If you want to display the sweet alert after ajax post back. ViewBag does not work like what you want and it is no need.
ViewBag is just an object that gets passed to the view when you render the page. It doesn't make any sense to use that with AJAX; your server-side Razor code runs on initial server render only.
The correct way is to add the data to response data.
Change like below:
<script>
$.ajax({
type: "POST",
url: "/home/AddPurchaseOrder",
contentType: "application/json",
data: JSON.stringify({ "Id": 5, "PurchaseOrderNo": "2342342424" }),
success: function (response) {
Swal.fire({
title: "Successfully Added!",
text: response.orderNo, //change here...
icon: 'success',
confirmButtonClass: 'btn btn-primary',
buttonsStyling: false
})
},
failure: function (response) {
//...
}
});
</script>
Controller:
public class HomeController : Controller
{
[HttpPost]
public JsonResult AddPurchaseOrder([FromBody] PurchaseOrder purchaseOrder)
{
string id = purchaseOrder.Id.ToString();
purchaseOrder.OrderNo = DateTime.Now.ToString("yyyyMMdd") + id;
//ViewBag.OrderNo = purchaseOrder.PurchaseOrderNo;
return Json(new { Id= purchaseOrder.Id , OrderNo= purchaseOrder.PurchaseOrderNo });
}
}
I have a function attached to the error on my ajax but it wont show me any error messages for 500 response codes? I display the error message with xhr.responseText but its returning an empty string, can anyone tell me why?
$.ajax({
type: "PUT",
url: "/ajax/account/create_key",
data: { key_id: document.getElementById('account-key-value').value, expires_at: document.getElementById('account-key-expires').value },
success: function(result) {
// close modal
swal({
title: "That was a success!",
text: 'Your account key has been created.',
icon: "success",
button: "Okay!",
});
document.getElementById('account-keys-content').innerHTML = result;
},
error: function(xhr, ajaxOptions, thrownError) {
if(xhr.status == 400) {
swal({
title: "Opps!",
text: xhr.responseText,
icon: "error",
button: "Okay!",
});
}
else {
swal({
title: "Opps, something went wrong!",
text: xhr.responseText,
icon: "error",
button: "Okay!",
});
}
}
});
Im using Mvc in C#.net and extjs. My question is
how to get value from textfield then set it to a variable and send email to multiple recipient.
This is my code for sending an email, and i want to get the values from the Extjs textfield id and set the id to a variable in sending. Then i want to send email to multiple recipient.
{
xtype: 'toolbar',
flex: 1,
dock: 'bottom',
ui: 'footer',
layout: {
pack: 'end',
type: 'hbox'
},
items: [{
xtype: 'button',
text: 'Send Email',
itemId: 'sen',
//iconCls: 'cancel'
handler: function() {
var rec = Ext.getCmp("activityGrid").getSelectionModel().selected()[0]
Ext.Ajax.request({
url: '/tblt_UAT_hr/generatePreview',
method: 'POST',
params: {
// id: Ext.get("Uath_Id").getValue(),
desc: rec.get("pc_desc"),
uat_date: rec.get("UAT_date"),
pcno: rec.get("pc_no"),
name: rec.get("name"),
stkid: rec.get("Stkhid")
},
success: function(resp) {
var result = Ext.decode(resp.responseText);
if (result.success) {
Ext.Ajax.request({
url: '/tblt_UAT_hr/SendEmailsTo',
method: 'POST',
params: {
from: null,
to: Ext.getCmp('to').getValue(),
subject: Ext.getCmp('subject').getValue(),
body: Ext.getCmp('bod').getValue(),
file: result.file
},
success: function(resp) {},
failure: function() {}
});
} else
mask.hide();
},
failure: function() {
mask.hide();
}
});
}
}, {
xtype: 'button',
text: 'Cancel',
itemId: 'can',
//iconCls: 'save'
}]
}]
public JsonResult SendEmailsTo(string from, string to, string subject, string body, string file) {
if (file != "" && file != null) {
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Credentials = new System.Net.NetworkCredential("ga.ojt.sunga#gmail.com", "1993doris");
smtpServer.Port = 587; // Gmail works on this port
string newfile = Server.MapPath("~/Content/pdf") + "\\" + file;
Attachment attachment = new Attachment(newfile);
mail.From = new MailAddress("ga.ojt.sunga#gmail.com");
//mail.To.Add(emailAdd);
foreach(var address in to.Split(new [] {
";"
}, StringSplitOptions.RemoveEmptyEntries)) {
mail.To.Add(address);
}
mail.Subject = subject;
mail.Body = body;
mail.Attachments.Add(attachment);
smtpServer.EnableSsl = true;
smtpServer.Send(e);
// return Content("email sent", "text/plain");
}
return Json(new {
success = true, msg = "success"
}, JsonRequestBehavior.AllowGet);
}
Find the text field, with ComponentQuery or otherwise, call getValue on it and add it to params of a request call. Pseudo code:
var field = Ext.ComponentQuery.query('#fieldItemId')[0];
params:{
yourField:field.getValue();
}
I'm trying to post a messsage to a wall using FB.api
My perms are: 'email, read_stream, publish_stream' and my code is:
FB.getLoginStatus(function(response){
if(response.session) {
var accessToken = response.session.access_token;
var tokenUrl = "https://graph.facebook.com/me/feed?access_token=" + accessToken + "&callback=?";
var shareUserId = document.getElementById("shareHidden").value;
var shareTxtAreaMsg = document.getElementById("shareTxtArea").value;
console.log("friends user Id: " + shareUserId + " & " + "message: " + shareTxtAreaMsg);
var data = {
message: "shareTxtAreaMsg",
display: 'iframe',
caption: "Caption",
name: "Name",
picture: 'http://someDomain.com/Dev/img/share-force-wall-img.jpg',
link: "http://www.facebook.com/pages/someapp/XXXXXXXXXXX?sk=app_XXXXXXXXXXXXXX", // Go here if user click the picture
description: "Description field",
actions: [{ name: 'action_links text!', link: 'some link' }],
}
console.log(accessToken);
FB.api(tokenUrl, 'post', data, function(response){
if (response)
{
//console.log(response);
if (response.error)
{
console.log(response.error.message);
}
else
{
if (response.id)
console.log("Posted as post_id "+response.id);
else if (response.post_id)
console.log("Posted as post_id "+response.post_id);
else
console.log("Unknown Error");
}
}
});
}
});
When when try to post the message I'm getting a "(#3) App must be on whitelist" returned. Why is this happening?
Try FB.api('/me/feed'... instead of tokenUrl because FB.api will automatically add the full url prefix.