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?

Link to comment
Share on other sites

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'.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.