I have written code to hide row for some criteria. It is working for some time, now it is not working found that jQuery.fn.jQuery.init[1] is returning jQuery.fn.jQuery.init[1] for the method .closest('tr'). Can some one suggest it why this issue is causing?
function applyfilter(ele) {
$.ajax({
cache: false,
async: true,
type: "POST",
dataType: "json",
url: "WebForm4.aspx/Calc",
data: "",
contentType: "application/json; charset=utf-8",
success: function (response) {
if (response.d > range) {
var row = $(ele).closest('tr');
var tr = $(row)[0];
$(row).remove();
return true;
}
},
});
}
Related
I have a post request from jquery ajax to a ActionResult method as follow :
$("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) {
if ((e.keyCode == 120){
var GetReportLast5SellAndBuyURL="/Trd/SellInvoice/GetReportLast5SellAndBuy";
itemCode = $(this).val();
$.ajax({
type: "POST",
url: GetReportLast5SellAndBuyURL,
data: {ItemCode:itemCode},
//contentType: "application/json; charset=utf-8",
context: this,
processData: false
}).done(function (msg) { ... somethings ...});}
And in controller, ActionResult is :
[HttpPost]
public ActionResult GetReportLast5SellAndBuy(string ItemCode)
{ ... somthings ...}
But when ActionResult is called " ItemCode " is null... What's wrong with this chapter?
I tried different forms of this recipe, but the problem is still there..
try this:
$.ajax({
type: "POST",
url: GetReportLast5SellAndBuyURL,
data: JSON.stringify({ItemCode:itemCode}),
datatype: "JSON",
contentType: "application/json; charset=utf-8",
processData: false
}).done(function (msg) { ... somethings ...});}
Just comment processData:false in your script
$("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) {
if ((e.keyCode == 120){
var GetReportLast5SellAndBuyURL="/Trd/SellInvoice/GetReportLast5SellAndBuy";
itemCode = $(this).val();
$.ajax({
type: "POST",
url: GetReportLast5SellAndBuyURL,
data: {ItemCode:itemCode},
//contentType: "application/json; charset=utf-8",
context: this
// processData: false
}).done(function (msg) { ... somethings ...});}
well explained at [Setting processData to false in jQuery breaks my AJAX request
$("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) {
if ((e.keyCode == 120){
$.ajax({
type: "POST",
url: "/Trd/SellInvoice/GetReportLast5SellAndBuy?ItemCode="+$(this).val(),
contentType: "application/json",
context: this,
datatype: "JSON",
processData: false
}).done(function (msg) { ... somethings ...});}
// OR
$("#itemTextbox, #itemTextboxNew, #quantity1Textbox").on("keydown", function (e) {
if ((e.keyCode == 120){
$.ajax({
type: "POST",
url: "/Trd/SellInvoice/GetReportLast5SellAndBuy",
contentType: "application/json",
data:JSON.stringify({ItemCode:$(this).val()})
datatype: "JSON",
context: this,
processData: false
}).done(function (msg) { ... somethings ...});}
I have an Ajax call, that in the Success function, load a PartialView(html), in a container.
And I need to do "something" with a hiddenField value that it is in the loaded PartialView.
Trying $("#IdOfHiddenTextField").val() or a class selector and Jquery do not select the Html element.
How can I achieve that?
Actual code:
$.ajax({
url: '/apps/server',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (response) {
if (response.ok == "ok") {
esValido = true;
$("#divContenedorPaso2").html(response.vistaRazor);
if (response.modificoEmail) {
$("#popup-mensaje").html("Modification successfull");
$('#myModalAdvertencia').modal('show');
}
} else {
$("#divContenedorPaso2").html(response);
}
}
});
I need to do:
$.ajax({
url: '/apps/server',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (response) {
$("#divContenedorPaso2").html(response);
var submitSuccesfull = $("#IdOfHiddenTextField").val();
// this hidden element is inside de PartialView "response"
if (submitSuccesfull ) {
esValido = true;
$("#popup-mensaje").html("Modification successfull");
$('#myModalAdvertencia').modal('show');
} else {
esValido = true;
}
}
});
I don't know your code but i think you need something like this :
$.ajax({
url: "partialView.html",
success: function(response) {
var result = $(response).find("#IdOfHiddenTextField").val();
}
});
I have a toggle switch on my html which i would like to enable/disable a relay in arduino with.
On: call http://192.168.1.144:8000/1234!Q02=0$
Off: call http://192.168.1.144:8000/1234!Q02=1$
I don't want the url to be opened, i just want it to be called.
function getValue1() {
var isChecked = document.getElementById("button1").checked;
if(isChecked){
alert("button1 is checked");
} else {
alert("button1 is NOT checked");
}
}
My javascript code is working, but i dont know how to call the url.
Thanks.
you can also try this.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#btnCall").click(function(){
if($("button1").prop('checked')){
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://192.168.1.144:8000/1234!Q02=0$",
data: JSON.stringify(data), //yourData
success: function (data) {
console.log(data);
},
dataType: "json"
});
} else {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://192.168.1.144:8000/1234!Q02=1$",
data: JSON.stringify(data), //yourData
success: function (data) {
console.log(data);
},
dataType: "json"
});
}
});
});
</script>
Button:
$(document).ready(function() {
$("#btnCall").click(function(){
var isChecked = document.getElementById("button1").checked;
if(isChecked){
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://192.168.1.144:8000/1234!Q02=0$",
data: JSON.stringify(data), //yourData
success: function (data) {
console.log(data);
},
dataType: "json"
});
} else {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://192.168.1.144:8000/1234!Q02=1$",
data: JSON.stringify(data), //yourData
success: function (data) {
console.log(data);
},
dataType: "json"
});
}
});
});
I have a json which is . I just want to get specific data which is
obj['contacts']['name']
How can i get
obj['contacts']['name']
name on Contacts array
This is my code:
$.ajax({
type: 'GET',
dataType: 'json',
url: uri,
cache: false,
contentType: 'application/json',
success: function(data) {
for (var obj in data) {
console.log(obj['contacts']['name']);
}
}
});
In your case this is how you want get name from contacts
$.ajax({
type: 'GET',
dataType: 'json',
url: uri,
cache: false,
contentType: 'application/json',
success: function(data) {
if (!data.contacts) return;
var names = data.contacts.map(function(dt) {
return dt.name;
});
console.log(names);
}
});
Just enumerate the returned object "contacts" property:
$.ajax({
type: 'GET',
dataType: 'json',
url: uri,
cache: false,
contentType: 'application/json',
success: function(data) {
data.contacts.forEach(function(contact) {
console.log(contact.name);
});
}
});
I have 2 JS literals:
var obj1 = {
Add: function (id) {
$.ajax({
type: "POST",
data: JSON.stringify({
"id": id
}),
url: "Page.aspx/add",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
return jQuery.parseJSON(data.d || "null");
}
});
}
};
var obj2 = {
List: function (id) {
$.ajax({
type: "POST",
data: JSON.stringify({
"id": id
}),
url: "Page.aspx/list",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
return jQuery.parseJSON(data.d || "null");
}
});
}
};
And this is my document.ready:
$(document).ready(function () {
obj1.Add(1).done(function (data) {
alert('you added ' + data);
});
obj2.List().done(function (data) {
$.each(jQuery.parseJSON(data), function (i, item) {
// fill a combo box
});
});
});
jQuery just executes the first call and obj2.List() ain't called at all.
How to properly use the deffered objects in this case?
Change your Add and List function to RETURN the ajax object.
Add: function (id) {
return $.ajax({..
and
List: function (id) {
return $.ajax({...
This way - it will return the jqXHR obj which will return the deferred object.
This implement the Promise interface which has : the callbacks you are looking for.
edit :
look at this simple example which does work :
var obj1 = {
Add: function (id) {
return $.ajax({
type: "get",
data: JSON.stringify({
"id": 1
}),
url: "http://jsbin.com/AxisAmi/1/quiet",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("at success --"+data.data)
}
});
}
};
obj1.Add(2).done(function (a){alert("at done --"+a.data);});