AJAX response in alert box


#1

I have the following in my PHP function:

if($this->page->add_blog_post($post_title, $post_author, $post_content, $file_name))
{
	http_response_code(200);
	echo "The blogpost was successfully added to the database.";	
}

When I return that to a div:

$(responseMessages).text(response);

Everything works fine! However when I try to get the response in a alert box:

window.alert(response);

the insert is ok but I get all kind of extra data returned. How do I get that simple echo from the PHP in a alert box


#2

What extra data do you see in the alert?


#3

<br />
<b>Notice</b>:  Undefined variable: photo_path in <b>C:\wamp64\www\Flyingparadise\private\includes\classes\Controller\Admin\Page.php</b> on line <b>299</b><br />
<br />
<b>Notice</b>:  Undefined variable: i in <b>C:\wamp64\www\Flyingparadise\private\includes\classes\Controller\Admin\Page.php</b> on line <b>302</b><br />
<br />
<b>Notice</b>:  String offset cast occurred in <b>C:\wamp64\www\Flyingparadise\private\includes\classes\Controller\Admin\Page.php</b> on line <b>302</b><br />
<br />
<b>Notice</b>:  Undefined variable: i in <b>C:\wamp64\www\Flyingparadise\private\includes\classes\Controller\Admin\Page.php</b> on line <b>303</b><br />
<br />
<b>Notice</b>:  String offset cast occurred in <b>C:\wamp64\www\Flyingparadise\private\includes\classes\Controller\Admin\Page.php</b> on line <b>303</b><br />
<br />
<b>Notice</b>:  Undefined variable: i in <b>C:\wamp64\www\Flyingparadise\private\includes\classes\Controller\Admin\Page.php</b> on line <b>304</b><br />
<br />
<b>Notice</b>:  String offset cast occurred in <b>C:\wamp64\www\Flyingparadise\private\includes\classes\Controller\Admin\Page.php</b> on line <b>304</b><br />
<br />
<b>Notice</b>:  Undefined variable: new_deskt_path in <b>C:\wamp64\www\Flyingparadise\private\includes\classes\Controller\Admin\Page.php</b> on line <b>304</b><br />
<br />
<b>Notice</b>:  Undefined variable: Status in <b>C:\wamp64\www\Flyingparadise\private\includes\classes\Model\Dashboard.php</b> on line <b>208</b><br />

#4

Well, solve those notices, which you should do anyway, and the problem is gone :slight_smile:


#5

@ScallioXTX. Thank you very much for your attention. I should copy and paste a bit less than things probably go a lot faster. I feel very embarrassed.


#6

No worries. And indeed, it is most of the time better to take things slow and do them correct than rush it through and having to clean up the mess later.


#7

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.