Reputation: 672
I'm playing around with AJAX calls. Ive tried so many different approaches, googled my goggles off and i'm kinda stuck. I'm trying to pass multiple parameters through the ajax call that PHP can $_REQUEST.
$("#content").load("data2.php?page=" + this.id,hideLoader);
This picks up the id of a item. and that works! it sends and I can $_request it on data2.php.
So I added class to that and trying to pass it like this without luck:
$("#content").load("data2.php?page=" + this.id + "&category=" + this.class, hideLoader);
Any help greatly appreciated
Upvotes: 0
Views: 163
Reputation:
The correct one that your are looking for is:
Thus your code should look like this:
$("#content").load("data2.php?page=" + this.id + "&category=" + this.className, hideLoader);
and also, deepening on your ajax initialization; in your PHP you should use $_GET
or $_POST
.
Upvotes: 3
Reputation: 12904
Whenever you face this kind of Problem do an alert
of "data2.php?page=" + this.id + "&category=" + this.class
before calling load. e.g. first see the url before going there.
and use $_GET in your PHP code.
Upvotes: 0
Reputation: 227240
You should pass the GET data as a separate parameter.
$("#content").load("data2.php", "page=" + this.id + "&category=" + this.className, hideLoader);
Also, since you know that this is GET, you should use $_GET
instead of $_REQUEST
.
If you pass the data as an object, jQuery will use POST ($_POST
).
$("#content").load("data2.php", {page: this.id, category: this.className}, hideLoader);
EDIT: As @Omeid said, this.class
should be this.className
. Just remember that this.className
will give you all the classes on an element, separated by spaces.
Upvotes: 0