This is the JS code:
$('.makeFavorite').click(function() {
$.ajax({
type: POST,
url: make_favorite.php,
data: id= + $(this.id),
success: function(msg) {
alert('Data saved: ' + msg);
According to the docs, 'this' within a success callback is the options
object, so 'this.id' doesn't mean anything useful:
http://docs.jquery.com/Ajax/jQuery.ajax#options
Also, $(this.id) probably isn't anything useful either.
Maybe try this (untested):
$('.makeFavorite').click(function() {
Hi Can you show more code? I think showing an alert would be a good
idea.
On Sep 22, 12:38 am, suntrop [EMAIL PROTECTED] wrote:
HI there,
I want to insert two variables into the selector and an attribute. But
it doesn't work.
$('h1 a#' + this.id + ' img').attr({src : images/ + msg +
you concatenate a string with an object..
On 22 Sep., 10:16, suntrop [EMAIL PROTECTED] wrote:
This is the JS code:
$('.makeFavorite').click(function() {
$.ajax({
type: POST,
url: make_favorite.php,
data: id= + $(this.id),
Thanks Erik. It helped! The id is inserted correctly.
But the image isn't replaced correctly.
What code should I sow you more Makisa? The other code isn't affected
with this. What do you mean?
On 22 Sep., 10:26, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
you concatenate a string with an
But the image isn't replaced correctly
Perhaps try changing this line instead
$('#' + id + ' img').attr(src, images/+msg+.png);
There's no reason why that (or your line for that matter) wouldn't
work as long as the selector finds something and the value of the
src is a valid path on your
When write:
$('#' + id + ' img').attr(src, images/favorites.png);
… it works.
alert (msg) says favorites.
There must be something wrong with msg. If the variable is defined
before var favimg = favorites; and I insert favimg it works just
fine.
What could be wrong with msg? msg is what I echo
are you sure there is no white space getting returned in your echo?
if you have a line break (which you can't see in the returned value)
that could be throwing off the img src tag
maybe wash the returned value through a function stripping off leading
and trailing whitespace
No one could possibly have any idea what's wrong there (other than a lucky
guess), because we're not seeing your actual code.
Forget about PHP for the moment and look at what you get back from a View
Source in the browser. That's all the browser and its JavaScript interpreter
know about - your
Hi Michael, I didn't want to screw things up with the complete code,
because I thought it is a pretty simple thing :-)
So here is the whole code:
(I haven't a live page, it is only on my local machine)
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
Can you show more code?
The first variable comes from the object's (a element) id
doesn't make any sense
i think your problem is this.id, you have to show the entire code in
order for us to see what does this mean. try just to add a alert for
example to see what you get for this.id
On Sep 21, 7:38 am, suntrop [EMAIL PROTECTED] wrote:
HI there,
I want to insert two variables into the selector and
I can't get it either, what are you trying to accomplish?
$('h1 a#' + this.id') is not logical, you first need to reference some
a element to get it's ID, but in doing that you already wrote the
ID...
On Sep 21, 11:16 pm, FrenchiINLA [EMAIL PROTECTED] wrote:
i think your problem is this.id,
13 matches
Mail list logo