jquery function return 1

jquery function return

function myFunction(p1, p2) {
  var a = "";
    method: "POST",
    url: "/url",
    data: {p1: p1,p2: p2},
    success: function (data) {a = data.result;},
    error: function (data) {a = data.result;}
  return a;

Here is what the above code is Doing:
1. It’s calling a function called myFunction, which takes two parameters, p1 and p2.
2. It’s making an AJAX call to a URL, passing the parameters p1 and p2.
3. It’s returning the result of the AJAX call.

The problem is that the AJAX call is asynchronous, so the function returns before the AJAX call is complete.

The solution is to make the AJAX call synchronous.

Similar Posts