Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Using an API I am creating a forum using Javascript.

When a user clicks on the thread title on the index.html page they are taken to a page called thread.html on here I am using an API call to display the results for the thread with ID 1

var threadRequest = new Request.JSON({
  url: 'control.php?action=getThread&id=1',
  onSuccess: threadSuccess
    }).send();

My question is how would I change this so it knows which thread has been clicked so it knows which thread to call, I have tried

function callThread(thread){
  var threadRequest = new Request.JSON({
    url: 'control.php?action=getThread&id='+thread,
    onSuccess: threadSuccess
     }).send();
}

with thread being the foreign key in the table linked to the API.

The thread titles are displayed like so

var jsonRequest = new Request.JSON({
    url: 'control.php?action=getThreadList',
    onSuccess: ajaxSuccess

}).send();

This is the threadSuccess function as well

function threadSuccess (jArray){
    jArray.each(function(post){
        var postObject = new PostItem(post.id, post.name, post.comment, post.thread);
        postObject.display().inject($('postList'));
    })
}

My question is do you get it so that the url string would do something like url: 'control.php?action=getThread&id=what ever number thread the user has clicked on

The post table contains the fields id, name, comment, timestamp and thread (this will define which thread the post will be in.)

and a thread table contains id and title.

share|improve this question
    
is there a question in this? when you say you tried, did it not work? what didn't work? seems reasonable and straightforward - ignoring the why and what you expose from the server, seo etc. one thing you can do is set url to control.php, method to get and pass an object as data with key->value pairs, easier to manage –  Dimitar Christoff May 5 '13 at 20:49
    
My question is what do I need to do so it does something like url: 'control.php?action=getThread&id=what ever number thread the user has clicked on'In other words if the user clicks on thread number 5 is will add a 5 after the equals sign. –  joshuahornby10 May 5 '13 at 21:55
    
No errors came when it didn't work the screen was just blank,in other words the query failed. –  joshuahornby10 May 6 '13 at 8:56

1 Answer 1

When you're outputting your links, do something like:

<div class="thread" data-id="{{ID from database}}">Thread</div>

document.querySelector('.thread').addEventListener('click', function(e){
    var id = e.currentTarget.getAttribute('data-id');
    callThread(id);
}, false);

The question you're asking is slightly confusingly worded, but this is the way I'd approach it if I were trying to achieve what I think you are!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.