SimplePortal

Support => English Support => Topic started by: ExWizzard on August 02, 2010, 11:32:51 PM

Title: Javascript and php blocks
Post by: ExWizzard on August 02, 2010, 11:32:51 PM
Hi,
I added this (http://www.yvoschaap.com/weblog/ajax_inline_instant_update_text_20/) script to a php block but there seem to be some issues that only happen inside the block. I tested the script on a test site and it worked as advertised here (http://www.yvoschaap.com/instantedit/).

The problem is that inside the php block when i try to save the text it does not reload "itself" instead i have to refresh the whole page to see the result. The error message is this:

Code: [Select]
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://www.sitename.com/instantedit.js :: anonymous :: line 52" data: no]
line 52:

Code: [Select]

50 if (!this.ocupado()) {
51 this._xh.open("GET",urlget,false);
52 this._xh.send(datos);
53 if (this._xh.readyState == 4 && this._xh.status == 200) {
54 return this._xh.responseText;
55 }

Also i load the script with this code

Code: [Select]
echo'<script type="text/javascript" src="instantedit.js"></script>';
I also tried loading the script from index.template.php but it seemed to have no effect to the contents of the block.
Thanks
Title: Re: Javascript and php blocks
Post by: AngelinaBelle on August 10, 2010, 07:53:58 AM
AJAX can sometimes be tricky, and I'm no AJAX expert.
Do you have a shoutbox enabled?
Does it work?
Are the two blocks on the same page?
Title: Re: Javascript and php blocks
Post by: ccbtimewiz on August 13, 2010, 12:59:07 AM
Were you able to figure this out, ExWizzard?
Title: Re: Javascript and php blocks
Post by: Nathaniel on September 21, 2010, 10:03:25 PM
Cool script, worked fine for me.

Below is the code I used in my Custom PHP block.
Code: [Select]
$string = file_exists('test.txt') ? file_get_contents('test.txt') : 'test';

echo '<script type="text/javascript" src="instantedit.js"></script>
<span id="userName" class="editText">', $string, '</span>';

Make sure that you have an 'update.php' file (make sure that it isn't called upgrade.phps), and the other relevant library files, in your main smf directory. You will also need to change the $string page of the code, if you want to store the data somewhere else, ie. not in the 'test.txt' file.
SimplePortal 2.3.8 © 2008-2024, SimplePortal