PHP Skipping JavaScript

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hey guys,

For some reason when I try the following:

echo "<div id='AjaxResponse'><script type=\"text/javascript\">success();</script></div>";

in PHP, no message is returned and all that is there when I use Inspect Element is:

"<div id='AjaxResponse'></div>"

Can somebody help please?

EDIT: This only seems to happen when receiving the response through Ajax
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Okay here's my Contact.html page:
Here's the page the Ajax sends the request to:

Is that all you need?
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
Try
PHP:
echo('<div id="AjaxResponse"><script>success();</script></div>');

or if you are dead set on declaring the MIME

PHP:
echo('<div id="AjaxResponse"><script type="text/javascript">success();</script></div>');

text/javascript is the default MIME and doesn't need to be declared.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,457
Search:

PHP:
$q = "SELECT * FROM message ORDER BY id DESC LIMIT 0, 1";
$r = mysql_query($q);
 
if(mysql_num_rows($r)>0): //table is non-empty
while($row = mysql_fetch_assoc($r)):
        $id = 0;
        $id = $row['id'];
endwhile;
endif;

replace with:
PHP:
$q = "SELECT * FROM message ORDER BY id DESC LIMIT 1";
$r = mysql_query($q);
 
if(mysql_num_rows($r)>0){ //table is non-empty
while($row = mysql_fetch_assoc($r)){
        $id = $row['id'];
}
}

I don't know why you do $id = $id+1?

Search:
PHP:
if($username == " " || !isset($username) && !isset($email) && !isset($password)){
echo "<span id='cc'><script type=\"text/javascript\">error();</script></span>";
}elseif(isset($username) && isset($email) && isset($password)){
mysql_query("INSERT INTO message (name, subject, message,id)
VALUES ('$new_name', '$email', '$password', '$id')");
echo "<span id='cc'><script type=\"text/javascript\">success();</script></span>";
  header('Refresh: 2; /site/contact.html');
}
else{
}
mysql_close();

Replace with:
PHP:
if(empty($username) && empty($email) && empty($password)){
    echo "<span id=\"cc\"><script type=\"text/javascript\">error();</script></span>";
}
else if (!empty($username) && !empty($email) && !empty($password)){
    mysql_query("INSERT INTO message (name, subject, message,id) VALUES ('".$new_name."', '".$email."', '".$password."', '".$id."')");
    echo "<span id=\"cc\"><script type=\"text/javascript\">success();</script></span>";
    header('Refresh: 20; /site/contact.html');
}
else{
}
    mysql_close();
    echo "Disconnected.";
}
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
It seems to work without using Ajax to make the request.
When I do it without the Ajax, it sends me to the message_sent.php page and displays the notification.
I guess I'll have to make do with changing the header location inside of message_sent.php

Thanks for your help, Holmes - You never fail to answer my nooby questions!
 

Users who are viewing this thread

Top