I use AJAX to gather data from a MySQL database through PHP, but all the Javascript functions on the web page get stuck when I’m trying to call an API method using the gathered data.
AJAX code structure:
$.post(
"userdata.php",
{ id: ""+userid+"" },
function(data) {
// call my API when AJAX call completed
}
);
The above code works perfectly. For example I tried alert(data);, it alerts the requested user’s name.
My full code:
$.post(
"userdata.php",
{ id: ""+userid+"" },
function(data) {
$.formdata.clear();
$.formdata.addname(data);
}
);
My API also works fine. I think the error is because of the $ sign, like $.post and inside of it again $.formdata.
Any solution for this?
The
$symbol is a name to referencejQuery. Here you are trying to reference a property of jQuery calledformdata.The
formdataobject looks like something you’re written, since it hasclearandaddnamemethods. Try calling it without the dollar sign.