Jump to content

Problem with Ajax/Dojo, probably simple for you guys.


Sharp

Recommended Posts

ok, so I'm trying to set up one button to link to a php script that will read from a file and display the results on the page. Running the php file itself will diplay what I want, but I cant integrated it into the html page properly.....

 

The Javascript:

<script type="text/javascript" src="/dojoSrc/dojo.js"></script>

<script type="text/javascript">
dojo.require("dojo.dnd.*");
dojo.require("dojo.event.*");
dojo.require("dojo.widget.*");
dojo.require("dojo.widget.Button");
        
function byId(id){
	return document.getElementById(id);
}

function buttonReadPressed()
    {
        
        // bind button to script, function and form
        dojo.io.bind({
                       url: 'test2.php',
                       handler: updateStatus,
                    });
    }
    
function updateStatus(msg)
{		
msg = "<p>"+msg+"</p>"
if(elem = document.getElementById("thread1"))
elem.innerHTML = msg;
	}

function init(){
	var readButton = dojo.widget.byId('readButton');
	dojo.event.connect(readButton, 'onClick', 'buttonReadPressed')
}

dojo.event.connect(dojo, "loaded", "init");
</script>

 

the associated html

<button dojoType="button" id="readButton">View Sample Post</button>

<div id="thread1"></div>

 

what happens when I click the button is that just the word "load" is returned, like so

 

Before Click:

load1.gif

 

After Click:

load2.gif

 

 

I dont really think I need to post the php, because like I said, it runs fine..... I just can't get it's output to show up on the main page.

 

Any Ideas?

Yeah, I knew it was something simple.

 

I used code from another project that bound a different function to the button, and that function then called my updatestatus function. I copied the code, but left out the middle function, and forgot to update the updatestatus function from

 

function updateStatus(msg)
{}

 

to

function updateStatus(type, data, evt)
{ msg = data; }

 

just having it the first way made msg = type, which (apparently) is always 'load'.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.