0

I have this code that is supposed to trigger an ajax call for every count of likes from a php like system I made. I guess it doesn't call because of the html tags but I need something like that.

In the following code I know the user ,id and since I am calling it from a fetch_array from php and mysql

<span id="sh1_'.$statusid.'" onload="checkRate(\''.$user.'\',\'status\',\'2\',\''.$id.'\')" > 0</span>

However there are many status when the php loads, and when it finishes loading the page it doesn't trigger the onload functions. Is there a way to retrieve the id on each div that i download within the same loop?

5
  • post some code to support your question. Commented Feb 27, 2015 at 6:42
  • ok, I forgot to copy it, thas why it didnt appeared Commented Feb 27, 2015 at 6:45
  • the last para is still not understandable .. What is that you mean by multiple statuses ? id on each div that i download ? Commented Feb 27, 2015 at 7:05
  • I do a call on php and get the status on my profile. The problem is tha I am trying to trigger a function for each status after I get the posts, I guess I have to get the results on the fly instead of waiting to load the page. Commented Feb 27, 2015 at 7:16
  • Show checkRate function. Is there any errors in console? Commented Feb 27, 2015 at 7:27

2 Answers 2

1

From what I can see after some googling, there is no onload event on span elements.

Maybe you could use onload on the body element to trigger your code?

Sign up to request clarification or add additional context in comments.

1 Comment

I got it, I was trying to do the calls in javascript when I should've got all the info in the php and echo it with the the posts and then update when people click on the like button. I am doing a like/nolike for comments and I was trying to get the results on loading the page, but instead I have to get them when I output the comments from php.
0

You can call a javascipt function every time you output the span. onload event is not supported by span tag, and won't be triggered. Use something like this:

<span id="sh1_'.$statusid.'" > 0</span>
?>
<script>
    checkRate('<?php print $user; ?>','status','2','<?php print $id; ?>');
</script>
<?php

1 Comment

Yes, I didn't think about it, yesterday I was burned out, also I don't need to call the javascript function since I can do all the gathering-info thing in the output.

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.