The idea with the page im working with (co. intra) is that it should never have to load again. All functionality is behind the scenes php and calling it javascript (XMLHttpRequest / Ajax).
I have a form that "submits" with javascript, values to JS vars and sent by ajax methods as POST to a php file.
The php file does some soap action and return eather error or success.
Now the problem.
Incase theres errors, i want to keep the form as it is. if not, i want to reload it.
why this is a problem is simply becourse i wouldint want to go edit the ajax function to check if i got errors back.
Currently the setup is like this:
Code:
+---------+------------+
| F O R M |return data|
+---------+------------+
If there are errors, they are outputted in the return data section along with javascript that reenables the submit button.
Incase there are no errors im outputting javascript that reloads the form, but it seems neather of thease are executed.
Does all javascript have to be loaded to the page at the initial load or is it possible to add javascript at a later time?
Instead of using the script, they use span tags with ids to identify the content, then use the innerHTML property to assign the data.
I suspect the script tags aren't working because the page was already loaded. You could check by sending back an alert('test value'); to see what it does.
Instead of having the response data refresh the form, it might be better to call the refresh directly based on the response. This is also more modular.
Everything added to the .innerHTML property is parsed by the browser, no matter when it was added. I use it frequently.
Try removing type="text/javascript", I've had problems with that for some reason.
It would be easier to tell what's wrong if you supplied a sample page which has the same problem.
I forgot to mention that the language attribute is deprecated and shouldn't be used at all. Usually, just <script> is enough since most browsers figure out what to do with the code anyway. But to be valid, the type attribute should be used.
Have you tried to simply send back an alert("Hello World!") script, like wirehopper suggested?
I'm assuming that the return data is posted back to the page where the forms and functions are, some AJAX applications use an iFrame or hidden frame as a cache for the loaded data. It doesn't look like that's the case here though.
btw, the javascript: part isn't needed in event attributes like onclick. It's only neccessary for href atributes and such where JavaScript code isn't expected.
Another idea would be to have the server return a javascript function, and after the response from the server is received and the code is posted at the client, use the response handler to call the returned function code.
The problem seems to be in executing the code, not the code itself. By forcing execution with a function call to it, you should be all set. A quick test would be to modify the
Another idea would be to have the server return a javascript function, and after the response from the server is received and the code is posted at the client, use the response handler to call the returned function code.
The problem seems to be in executing the code, not the code itself. By forcing execution with a function call to it, you should be all set. A quick test would be to modify the