[Help] How create the core.php for this archive ajax

silviosing

New Member
Joined
Mar 19, 2013
Messages
16
Reaction score
0
i need to create the file core.php for this file whit ajax

HTML:
function show(val) {
	$("#content").empty().append('<center><img src="images/load.gif"><br>Loading web module,Please wait...</center>');

	$.ajax(
	{

		type: "POST",
		url: "includes/core.php",
		data: "content=" + val + "&module=content",
		cache: false,
		success: function(msg)
		{
			$("#content").empty().append(msg).hide().fadeIn("slow");

		}
	});	

}
 

milenium

New Member
Joined
Feb 23, 2015
Messages
24
Reaction score
5
One of the ways you can organize your core.php is the following:
PHP:
<?php
if ($_POST['module'] == 'content') {
    switch ($_POST['content']) {
        case 'blabla':
            // TODO

            break;

        case 'blabla2':
            // TODO

            break;

        default:
            break;
    }
}
?>

Note: you better add some checks for $_POST

Your links should look like this:
PHP:
<a href="#" onClick="show('blabla')">Link 1</a>
    <a href="#" onClick="show('blabla2')">Link 2</a>
 

silviosing

New Member
Joined
Mar 19, 2013
Messages
16
Reaction score
0
mmmm and ir i need links look like this:

Code:
 <a onClick="show('news')">Main Page</a>
 

cse

New Member
Joined
Apr 7, 2015
Messages
20
Reaction score
19
PHP:
<?php
if(isset($_POST['content']) && $_POST['module'] === 'content') {
	$content = trim((int)$_POST['content']);
	$content = htmlspecialchars($content);
	$outp = '';

	if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest' || !filter_var($content, FILTER_VALIDATE_INT) || !preg_match('/^[0-9]{1,11}$/', $content)) {
		$outp = 'not found message';
	} else {
		switch($content) {
			case '1':
			$outp = 'blabla #1';
			break;

			case '2':
			$outp = 'blabla #2';
			break;

			case '40':
			$outp = 'blabla #40';
			break;
		}
	}

	echo '".htmlentities($outp)."';
}
?>


PHP:
<input type='button' value='load content 1' onclick='show("1")' />
/* will output blabla #1 onclick */


PHP:
<input type='button' value='load content 2' onclick='show("2")' />
/* will output blabla #2 onclick */


PHP:
<input type='button' value='load content 40' onclick='show("40")' />
/* will output blabla #40 onclick */
 
Last edited:
  • Like
Reactions: satanism