maxhugen
Posts: 272
|
| Posted: 07/22/2008, 10:29 PM |
|
In a 'story' webpage, I've added a form 'vote'. This allows readers to rate a Story (1-5, like YouTube).
I've added the AJAX UpdateDb feature to Insert a new record to the table 'vote'. This is working OK.
However, after the AJAX call finishes, it is refetching the webpage, and I'm at a loss to understand how/why.
I added an alert to the ajax call:
onSuccess: function(transport) {
document.getElementById("message").innerHTML="Thanks for rating this Story!";
alert("OK");
},
onFailure: function(transport) {
document.getElementById("message").innerHTML="Sorry, there was a problem adding your Rating.";
alert("Not OK");
}
The message text appears as it should, and the alert displays - and then it refetches the page - although I note that the URL has now has a "?" appended at the end of it, eg:
http://www.chrisarminson.com/Cloetes_Folly.php?
Can anyone suggest why it might be refetching the page?
MTIA
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
datadoit
|
| Posted: 07/23/2008, 5:51 AM |
|
I don't have CCS4 to be able to see how CCS is working with AJAX, but
from looking at your page source your <form> has a method of posting
along with an action. Try removing those. All of the magic is
triggered in the insert button's onClick event.
|
|
|
 |
jjrjr1
Posts: 942
|
| Posted: 07/23/2008, 9:31 AM |
|
Hi
Data is right.
Change your insert button from a type submit to button only and ensured the OnCLick event points to the ajax insert routine.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
maxhugen
Posts: 272
|
| Posted: 07/23/2008, 9:34 PM |
|
Thanks data, John
I'd come to the same conclusion: that the button was also triggering a 'submit'.
So, I removed the 'Operation' property (it was Insert) from the CCS Button. This hasn't prevented the refetch, but what I did discover is that the Ajax Insert wasn't happening after all !
At this point, I think I have several problems:
1. The CCS-generated ajax code is not getting the value of the radio control. The CCS javascript function getSameLevelCtl() used in the ajax javascript function doesn't handle radio controls, and returns a Null. I changed this to custom code to get the value, so that's OK now.
2. The CCS ajax php code isn't handling the timestamp field - it's trying to insert a NULL.
3. I have to use a 'CCS' form button, to assign the feature's Start event. If I try to use a plain HTML button, the ajax feature doesn't 'see' it. However, the feature uses the CCS javascript function addEventHandler() to assign the ajax function on the click event. I've struck problems with this before... there doesn't seem to be a way to cancel the button's default action. Hence, the form is still submitted, and therefore the page is refetched.
<sigh> Back to CCS support....
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/24/2008, 7:17 AM |
|
Hi again
What you need to do is not change the operation of the submit button but change it's type to button. That will stop the pahe from reloading.
The next thing you need to do is take a look at the addeventhandler line to see what onClick event is being called by the button. It should point to an AJAX routine calling the updatedb service.
Check and be sure the service is updating or insterting the new data as required.
Have fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
maxhugen
Posts: 272
|
| Posted: 07/24/2008, 4:26 PM |
|
Hi John
I got myself confused because all 'buttons' in CCS forms are <input> elements, either with type "submit", or as I tend to use, type "img", depending on the style you choose in the Record builder.
In a POST, whatever was clicked must be passed in the POST, as CCS code checks which was pressed in function Operation(), and thus knows what to do next (Add, Insert, Delete etc).
I was surprised to learn that there is also a HTML element <button> which works in a similar way to using <input>. Apparently, browsers may render these slightly differently, such as displaying an up/down 'motion'. I learn something every day!
As to the Ajax UpdateDb service, CCS support has confirmed that there is a bug in their javascript function getSameLevelCtl(), whereby a radio control is not handled properly. I'm waiting to see what they come up with.
Despite the lack of a php debugger (hell, I miss that!), I've located roughly where the error in their php Ajax code is, that's not handling dates correctly. CCS haven't responded to that one yet.
I seem to have a knack for finding CCS bugs - just lucky I guess.
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/25/2008, 3:24 PM |
|
Hi
Be aware thet there are other bugs in the CCS update code as to how ytext areas are handled. especially trext areas with FCKeditor attached.
The problem is in some cases the newline character is placed in the database and other times the break tag is used. Yes is aware of this problem as well. No fix for it yet but I have a work around for that.
If you have a work around for the date problem, I would appreciate a little description of the problem and how you fixed it. I have not come across this yet.
Have fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
maxhugen
Posts: 272
|
| Posted: 07/25/2008, 7:07 PM |
|
Hi John
I've now got it working - as an include page - but I had to modify the ajax javascript to get the radio button value.
Also modified the php code to get around the date issue. My date field is called 'timestamp', and the code that fails is the line:
$Service->DataSource->cp["timestamp"]->SetValue($Service->GetInputData("ctrltimestamp"));
As $Service->GetInputData("ctrltimestamp") correctly returns the JSON value, I assume the prob is with the GetValue() function.
I worked around it by compiling my own SQL statement, and running it through my own db connection. That is, I commented out the echo $Service->Execute() statement, and used my own echo $db->query($sql).
Totally ugly, but at least it works for now. I'm waiting for CCS support to see if they can/will patch this, and I'll advise back here when I hear from them.
BTW, after finding and reporting another bug, CCS pointed out that the latest patch is 4.01.00.06, available at http://support.yessoftware.com/updates.asp
Cheers, Max
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
solesz
Posts: 137
|
| Posted: 09/06/2008, 12:46 PM |
|
Hi All,
I am using CodeCharge with ASP.
I also stuck with AJAX updateDB.
Let share the experiences:
1. I created a very simple "Record control" on a new ccs page, name : "mp_co"
2. I inserted an Image Link, name "ImageLink1" The function of this link to update a field within the displayed record.
3. I assigned a "Feature" to the "Record control" element. (To ImageLink1 can not, there is no option)
4. AJAX - updateDB feature.
Then nothing happen.
I made a careful investigation.
1. Javascript Addevent handler added to the ImageLink1 object.
2. In CCS, in HTML editor almost at the bottom there is a <--UpdateDB .. --> line, where a code snippet will be inserted at run-time, by the asp code. You can easily see the result in your web browser, if you clik to the View Source code.
And what you see:
<!-- BEGINF UpdateDB UpdateDB1 --><script language="JavaScript" type="text/javascript">document.getElementById("mp_co").ccsmp_coUpdateDB1Data = {"urlmp_co_id": 3, " expr23": 2};</script><!-- ENDF UpdateDB UpdateDB1 -->
"mp_co" will get a new property, name: ccsmp_coUpdateDB1Data
This property will have the value: {"urlmp_co_id": 3, " expr23": 2}
OH, YES. this parameter should be passed back to the server, where an asp code will process this information.
BUT !!!! This value will NEVER be passed. Why? scroll down.
When you click the ImageLink1, then the eventhandler will invoke the AJAX function in the page. Looks somewhat so:
//Initialize mp_coUpdateDB1 @22-1CA41E42
function mp_coUpdateDB1_start(sender) {
window.alert(sender.name); //******************************
var reqBody = "";
var toSend = new Object();
!!!!!!!! if (sender.ccsmp_coUpdateDB1Data) { !!!!!!!!
toSend = sender.ccsmp_coUpdateDB1Data;
}
reqBody = Object.toJSON(toSend);
url = "?callbackControl=mp_coUpdateDB1";
new Ajax.Request(url, {
method: 'post',
postBody: reqBody,
onSuccess: function(transport) {
},
onFailure: function(transport) {
}
});
}
//End Initialize mp_coUpdateDB1
There is one line with //****************** I added later to the code.
If you do this, then you will see, the sender object is ImageLink1. It is normal.
But OH NOOOO. The property, which has been added to "mp_co", now queried from "ImageLink1".
This point, when I turned to CodeCharge support.
Peter.
|
 |
 |
|