Reputation: 1884
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?
Upvotes: 0
Views: 205
Reputation: 18848
The $
symbol is a name to reference jQuery
. Here you are trying to reference a property of jQuery called formdata
.
The formdata
object looks like something you're written, since it has clear
and addname
methods. Try calling it without the dollar sign.
formdata.clear();
formdata.addname(data);
Upvotes: 3