Loading ...
Sorry, an error occurred while loading the content.

Re: Dialog handleSucess eval(response)

Expand Messages
  • Caridy Patiño Mayea
    Hi Jeremy, If the response text is not a javascript s segment, why you try to evaluate it? Just use the innerHTML to display it on the page. In case you need
    Message 1 of 5 , Sep 4 2:13 PM
    • 0 Attachment
      Hi Jeremy,

      If the response text is not a javascript's segment, why you try to
      evaluate it? Just use the innerHTML to display it on the page.

      In case you need to combine HTML chunks with javascript chunks in your
      response, then you can use the Dispatcher plugin. See the examples here:
      http://www.bubbling-library.com/eng/api/docs/plugins/dispatcher/examples

      Best Regards,
      Caridy
      http://www.bubbling-library.com/

      --- In ydn-javascript@yahoogroups.com, Jeremy Coates <lists@...> wrote:
      >
      > Hi Caridy,
      >
      > Caridy Patiño Mayea wrote:
      > > Hi Jeremy,
      > >
      > > Can you post an example to check it?
      > >
      > OK here goes - complete sample:
      >
      > <script type="text/javascript">
      > YAHOO.namespace("example.container");
      >
      > function passwordreset_init() {
      >
      > // Define various event handlers for Dialog
      > var handleSubmit = function() {
      > this.submit();
      > };
      > var handleCancel = function() {
      > this.cancel();
      > };
      >
      > var handleSuccess = function(o) {
      > var response = o.responseText;
      > response = response.split("<!")[0];
      >
      > document.getElementById("passwordreset-response").innerHTML = response;
      > eval(response);
      >
      >
      > document.getElementById('passwordreset-username').value = '';
      >
      > document.getElementById('passwordreset-email').value = '';
      > };
      >
      > var handleFailure = function(o) {
      > alert("Submission failed: " + o.status);
      > };
      >
      > YAHOO.example.container.passwordreset = new
      > YAHOO.widget.Dialog('passwordreset', {
      >
      > fixedcenter:true,
      >
      > visible:false,
      >
      > width:'350px',
      >
      > constraintoviewport:true,
      >
      > modal:true,
      >
      > draggable:false,
      >
      > effect:{ effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5 },
      >
      > buttons:[ { text:"Reset Password", handler:handleSubmit,
      isDefault:true },
      >
      >

      > { text:"Cancel", handler:handleCancel } ]
      > }
      > );
      >
      >
      YAHOO.example.container.passwordreset.callback =
      > { success: handleSuccess,
      > failure:
      > handleFailure };
      >
      > // Validate the entries in the form to require
      > that both first and last name are entered
      >
      YAHOO.example.container.passwordreset.validate =
      > function() {
      > var data = this.getData();
      > if (data.username == "") {
      > alert("Please enter your username");
      > return false;
      > } else if (data.email == "") {
      > alert("Please enter your email
      address");
      > return false;
      > } else {
      > return true;
      > }
      > };
      >
      > YAHOO.example.container.passwordreset.render();
      >
      >
      > YAHOO.util.Event.addListener('show-passwordreset', 'click',
      > YAHOO.example.container.passwordreset.show,
      > YAHOO.example.container.passwordreset, true);
      >
      >
      > document.getElementById('passwordreset').style.display = 'block';
      > }
      >
      > YAHOO.util.Event.addListener(window, "load",
      > passwordreset_init);
      >
      > </script>
      > <div id="show-passwordreset" class="text"><a href="#"
      > onclick="return false;" accesskey="f"><span
      > class="accesskey">F</span>orgotten Password?</a></div>
      > <div id="passwordreset" style="visibility: hidden;
      > display: none;">
      > <div class="hd">Reset My Password</div>
      > <div class="bd">
      > <form method="post" action="passwordreset.txt">
      > <div><span><input type="text"
      > name="username" id="passwordreset-username" value="" accesskey="n"
      > onfocus="this.className='input-on';" onblur="this.className='input';"
      > /></span><label for="passwordreset-username">User<span
      > class="accesskey">n</span>ame:</label></div>
      > <div><span><input type="text" name="email"
      > id="passwordreset-email" value="" accesskey="e"
      > onfocus="this.className='input-on';" onblur="this.className='input';"
      > /></span><label for="passwordreset-email"><span
      > class="accesskey">E</span>mail:</label></div>
      > </form>
      > </div>
      > </div>
      >
      >
      > And the Ajax reponse in passwordreset.txt is simply:
      >
      > Your new Password has been sent to you via email
      >
      > The error is on the eval line according to Firefox - so I'm presuming
      > that the simple text string returned is being evaluated (because I've
      > asked it to be) and since it's not Javascript only plain text then
      it is
      > failing?
      >
      > > Btw, in your code, the string in "response" will be executed twice in
      > > firefox, you may consider to use the dispatcher plugin to execute
      > > remote javascript code's segment.
      > >
      >
      > How's that work? Can you post an example please?
      >
      > Regards,
      > Jeremy
      >
      > > Best Regards,
      > > Caridy (caridy at gmail.com)
      > > http://www.bubbling-library.com/
      > >
      > > --- In ydn-javascript@yahoogroups.com, Jeremy Coates <lists@> wrote:
      > >
      > >> Hi,
      > >>
      > >> Using handleSuccess as shown in the yui examples, I get an error:
      > >> "missing ; before statement" in Firefox error console.
      > >>
      > >> var handleSuccess = function(o) {
      > >> var response = o.responseText;
      > >> response = response.split("<!")[0];
      > >> document.getElementById("mydiv").innerHTML = response;
      > >> eval(response);
      > >> };
      > >>
      > >> I'm simply returning some text from the server - nothing else and it
      > >> seems to work fine. Am I missing something or do I have to parse the
      > >> response text before the eval to get rid of the error?
      > >>
      > >> TIA,
      > >> Jeremy
      > >>
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.