2

I have a each loop that should send a private message:

[...].each(function () { $.get('board.php?func=list&id=' + (this.text) + '&send=Please read the board rules'); });

When I do 'alert(this.text);' within the each loop, everything works fine. But when I concatenate it with the string of the get Request, it doesn't work. Do I miss something?

4
  • What exactly is this, show us the scope this is used in? If it's an element, it should probably be $(this).text() Commented Jun 2, 2013 at 10:30
  • Try defining the url separately and logging it to see where the error lies e.g. [...].each(function () { var url = 'board.php?func=list&id=' + (this.text) + '&send=Please read the board rules'; console.log(url); $.get(url); }); Commented Jun 2, 2013 at 10:31
  • @adeneo: The data I am working with, comes from another get request. I am now working within the callback function: $(data from get request).find('#boardmembers').children('members').each[...]. The rest is above ;) Commented Jun 2, 2013 at 10:38
  • Then you are working with elements, and inside each() this will be a native DOM element, which has no text property, you should be using $(this).text() to get the text, did you try that. Commented Jun 2, 2013 at 10:41

1 Answer 1

2

Maybe writing it a little more verbose with $.ajax makes it clearer why you would you need to use $(this).text(), and not this.text

$(data from get request).find('#boardmembers')
                        .children('members')
                        .each(function() { 
                             $.ajax({
                                 type: 'GET',
                                 url : 'board.php',
                                 data: {
                                        func:'list',
                                        id  : $(this).text(),
                                        send: 'Please read the board rules'
                                 }
                             });
                        });
Sign up to request clarification or add additional context in comments.

1 Comment

In future I will just use this style. Helped a lot. Thanks man!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.