View Full Version : Using Yahoo Connection api

31 Dec 2011, 14:30
The vbulletin pages load the yahoo-dom-event and connection libraries.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/yui/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js?v=387"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/yui/2.9.0/build/connection/connection-min.js?v=387"></script>

I want to use those libraries to make ajax requests. I don't want to pack jquery on top of all the libraries that are already loaded.

So how would I make such a request?

Firstly, the documention for the yahoo connection manager states that "yahoo-min" is a prerequisite:

I tried to do an ajax request like this, but nothing happens:
var postData = "postid=12345&userid=$bbuserinfo[userid]&hash="+the_hash;

var callback = {
failure: handleFailure,
argument: ['foo','bar']
var handleSuccess = function(o){
if(o.responseText !== undefined){
div.innerHTML = "Transaction id: " + o.tId;
div.innerHTML += "HTTP status: " + o.status;
div.innerHTML += "Status code message: " + o.statusText;
div.innerHTML += "<li>HTTP headers: <ul>" + o.getAllResponseHeaders + "</ul></li>";
div.innerHTML += "PHP response: " + o.responseText;
div.innerHTML += "Argument object: " + o.argument;
var handleFailure= function(o){

var request = YAHOO.util.Connect.asyncRequest('POST', 'http://mydomain.com/myscript.php', callback, postData);

So how is the connection even working in vbulletin? Why is the connection manager loaded when it depends on the yahoo library?

31 Dec 2011, 15:32
I tried this out and it works for me. I did have to remove the "+ the_hash" because it wasn't defined, but I assumed you just didn't include that code. How do you know it's not working? I'd suggest using something like FireFox with FireBug if you're not already.

31 Dec 2011, 16:13
So you don't have to load the yahoo-min.js library as a dependency?

31 Dec 2011, 16:17
I just copied your code in to the footer template, made a few changes to get it to run (liike the 'the_hash' thing and changing the url). I changed it to call misc.php?do=ajax then put a plugin on misc_start that just has:

if ($_REQUEST['do'] == 'ajax')

Then using Firebug I could see that it was making the request and getting the "foo" response. So no, I didn't have to add any js files.

31 Dec 2011, 22:36
Okay, thanks. You are always very helpful, kh99!

--------------- Added 1325434992 at 1325434992 ---------------

I've had a look at Firebug now. It was a missing security token that was causing the problems.