Why are we sending the POST data as JSON in jQuery

I need to send data into controller. So I have to use ajax call to send it.

$  .ajax({        url: self.options.link,        data: {product_id: product, form_key: formKey, email: emailId, mobile: mobNo} }); 

Why and when we use the data:JSON.stringify({}); and data:{} for sending post data via ajax.

$  .ajax({        url: self.options.link,        data: JSON.stringify({product_id: product, form_key: formKey, email: emailId, mobile: mobNo}) }); 


Как в jQuery объединить несколько объектов?

допустим, есть объекты

<div id="div1"></div> <div id="div2"></div> 

Общее действие над ними можно совершить так:

$  ('#div1,#div2').toggleClass('hidden'); 

Но если мне надо объявить их как объекты js

var $  d1 = $  ('#div1'), $  d2 = $  ('#div2'); 

то как тогда их объединить?

Como hacer para retonar un valor de esta funcion en jquery

esta funcion me devuelve undefined, he intentado de varias maneras pero nada, me funciona bien si la hago una por una pero lo que quiero es ahorrar codigo y no hacer una por cada mes

   function buscador(mes,year){     var url="../controlador/funciones.php";   $  .ajax({   type: "POST",   url: url,   data: {"totalingresosbuscado":'elcodigo','buscado':mes,'tabla':'ingresos','campo':'mes','year':year},  success: function(data)           {       return data;             }   });    }  var enero = buscador(Mayo,2019);  console.log(enero);

Hacer focus en un boton dependiendo del valor de un atributo javascript – jquery

var idProducto = $  (this).parent().parent().parent().parent().children().next("tr:visible").children().children().children("button").attr("idproducto"); 

aquí agarro el valor del atributo, Y quiero hacerle focus al boton que tiene ese valor (idProducto)

$  (this).parent().parent().parent().parent().children().next("tr:visible").children().children().children("button").focus(); 

se traen varios registros, y me toca hacerlo de esta forma, Gracias

search json data in javascript and jQuery

If i search any json data to given depends on keyword in input filed i can’t view any data in below json datas. what is the solution for this. I have attached javascript code

 <script type="text/javascript">           $  (document).ready(function () {              //declare a global variable             var filterVal;             //check if sessionStorage exists and if so, if there is a var called fillTerm             //if not, set it to a default value (all)              $  .getJSON('openingdata.json', function(data) {                $  .each(data, function(key, full){                 });              });              if (sessionStorage && sessionStorage.getItem("filTerm")) {                 filterVal = sessionStorage.getItem("filTerm");              }              else {                 filterVal = "all";                 sessionStorage.setItem("filTerm", filterVal);             }               //now let's attach some interaction to our buttons             /*$  (".searchBtn").on("click", function () {                 //get the value for our filter                 filterVal = $  (this).attr("data-filter");                 //store it in the session storage                 sessionStorage.setItem("filTerm", filterVal);                 console.log(sessionStorage);                 console.log(filterVal);                 //call our view update function                 updateView();             });*/              $  ("#searchBtn").on("click",function(){                 filterVal = $  ('#searchEntry').val();                 sessionStorage.setItem("filTerm", filterVal);                 updateView();             });              $  ("#searchEntry").on("keypress",function(e){                 if (e.keyCode == 13) {                   filterVal = $  ('#searchEntry').val();                   sessionStorage.setItem("filTerm", filterVal);                   updateView();                 }             });                //this is the function that manipulates the UI             function updateView() {                 //default situation: all is visible                 if (!filterVal || filterVal === "all") {                     $  ('.filter').show();                 }                     //hide all and show filtered values                 else {                     $  (".filter").hide();                     $  ('.filter').filter('.' + filterVal).show();                      console.log("searchTerm");                     console.log("filterVal");                 }             };             //update the view when the page loads             updateView();          }); </script> 

Apply a jQuery whitespace trim to an adminhtml filter input

My goal is to load a simple jQuery function to trim any whitespace in an admin backend filter input. The use case involves a scanner inputting codes with spaces that will turn up no results.

I have tried a couple methods involving loading the script through an XML layout update as a phtml block, or because the filter is under adminhtml/ui_component, updating the column to load in my script as a component. The methods I have attempted have failed for one reason or another, whether because the load order is failing because I’ve failed to properly use requirejs in this case, or because the script cannot access the element.

The script is:

define([      'jquery'  ],  $  (function () {     $  ("input[name='code']").bind('input', function(){       $  (this).val(function(_, v){         return v.replace(/\s+/g, '');       });     });   })  

In essence, what is the best/recommended way to load this script so that it will strip whitespace out of an adminhtml filter?

Jquery events Draggable,Resizeable doesnot work with html ” Tag

I am using Jquery Ui in a project where html objects like and are dragged and resized but for interactive SVG I had to go for to draw and change svg element. But at this stage i am not able to drag and resize the element.

I have tried this to make it draggable and resizeable

var newcanvas = $ (‘<[object]>’).attr(“data”,”http://upload.wikimedia.org/wikipedia/en/8/80/Wikipedia-logo-v2.svg”).css(“width”,”100%”);

newcanvas.resizable(); newcanvas.draggable();

Note*: newcanvas is a dynamic added object to some div but the same cas is working correct with tag and other but not with object tag (Any kind of help will be appreciated)