0

I have the following scenario:

function myHandlerFunction(data){
   //do anything with data...
}

function ajaxHTTP(url, dataPost, funct){
   $.ajax({
       type: "POST",
       url: url,
       data: dataPost,
       dataType: "html",
       success: function(data){
            funct(data); //Response is coming as plain-text
       },
       error: function(errMsg) { } //To see the error message, use the var of parameter
   });
}

ajaxHTTP("https://example.com", { field: "value" }, myHandlerFunction);

It is working well, but I need to pass parameters in method myHandlerFunction, how I can do that?

Is possible: ajaxHTTP("https://example.com", { field: "value" }, myHandlerFunction(arg1, arg2));

  • You are already passing argument while calling this function here `funct(data); //Response is coming as plain-text`, do you need more arguments? – Mesar ali Sep 13 '21 at 16:34
  • Yes, I think it can be dynamic. –  Sep 13 '21 at 16:36
  • if you pass argument here, where you'll use that argument? You are passing this function to `ajaxHTTP`, so that you can send data dynamically to it, `ajaxHTTP("https://example.com", { field: "value" }, myHandlerFunction);` – Mesar ali Sep 13 '21 at 16:40
  • I need to pass data through parameters in the function passed as one. Checking the answer. –  Sep 13 '21 at 16:48

0 Answers0