Jump to content

Javascript Alerts.


xyn

Recommended Posts

Hey.

I have an ajax code to run a small chat client.

The client works perfectly. although when i try

adding an alert to display instantly, I have problems.

 

Basically php is printing

"<script>alert('Notice:".$msg."');</script>";

then that is added along with the rest of the coding, then updated in the DIV

using

document.getElementById('myDiv').innerHTML =ajx;

 

I debugged my SQL. and it works perfectly. its just the Javascript which wont work.

Link to comment
Share on other sites

  • 3 weeks later...

document.getElementById('myDiv').innerHTML =ajx;

--you can not execute javascript by innerHTML'ing it. It just doesn't work and I don't think it works on any browser. 

 

If you want to return a value from php down the ajax pipe and then alert it, you have to divide out the value from the other stuff returned using javascript functions and then alert it. Which means you will have to separate it or mark it some way on the server side so that the client side can separate it out. You could use json, or just surround it with some special characters server side:

<?php
    if ($sendmessage) { // if I have a special message set, I will send it
        echo '<!--**alertme**' . $sendmessage . '**-->';
    }
?>

--in the case above I would use javascript regular expression search functions on the ajax return value to find strings beginning with the opening html comment tag plus 2 *'s  plus 'alertme**' and ending with 2 *'s and the ending html comment tags.

Link to comment
Share on other sites

Hey.

I have an ajax code to run a small chat client.

The client works perfectly. although when i try

adding an alert to display instantly, I have problems.

 

Basically php is printing

"<script>alert('Notice:".$msg."');</script>";

then that is added along with the rest of the coding, then updated in the DIV

using

document.getElementById('myDiv').innerHTML =ajx;

 

I debugged my SQL. and it works perfectly. its just the Javascript which wont work.

 

I will suggest you to debugg the javascript in firebug in firefox. kindly check weather you are receiving the expected output in your javascript by alerting the response in js.

 

Regards

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.