unable to make ajax work to send form data - javascript

i am unable to see what is wrong with the below code. I simply want to submit a php variable to another php page. please don't say sessions as i know for sure sessions wont work for me here. all i want is to send the session variable to the next php page via ajax and without the user knowing it.
<?php
session_start();
$fname=$_SESSION['mail'];
?>
<!DOCTYPE HTML>
<html>
<title>Addressbook</title>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function(){
$.ajax({
url:"DbManipulate.php",
type:"POST",
data:"source1:"<?php echo $fname ?>""
});
}
</script>
<link rel="stylesheet" type="text/css" href="crudstyle.css" />
</head>
<body>
<div id="hidden_form_container" style="display:none;"></div>
<div id="mhead"><h2>Your Adressbook</h2></div>
<div id="note"> <span> your addressbook is connected to our servers :) </span></div>
<?php
echo $fname;
?>
<table id='demoajax' cellspacing="0">
</table>
<script type="text/javascript" src="script.js"></script>
</body>
</html>

Passing data as a object is not correct in your code. Please change as follows and try
data:{source1:"<?php echo $fname ?>"}

There is some syntax error in your data:value part in $.ajax() call
You should use
data: "source1=<? php echo $fname ?>"
or
data:{source1:"<? php echo $fname ?>"}

<?php
session_start();
$fname="surat";
?>
<!DOCTYPE HTML>
<html>
<title>Addressbook</title>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function(){
var sessioni='<?php echo $fname ?>';
$.ajax({
url:"DbManipulate.php",
type:"POST",
data:{source1:sessioni}
});
});
</script>
<link rel="stylesheet" type="text/css" href="crudstyle.css" />
</head>
<body>
<div id="hidden_form_container" style="display:none;"></div>
<div id="mhead"><h2>Your Adressbook</h2></div>
<div id="note"> <span> your addressbook is connected to our servers :) </span></div>
<?php
echo $fname;
?>
<table id='demoajax' cellspacing="0">
</table>
<script type="text/javascript" src="script.js"></script>
</body>
</html>

Related

Uncaught ReferenceError: myajax is not defined at HTMLButtonElement.onclick in WP

This code is for getting all posted post and its content using ajax in WP
Function.php in WP
add_action('wp_ajax_my_action','data_fetch');
add_action('wp_ajax_nopriv_my_action','data_fetch');
function data_fetch(){
$this_query = new WP_Query(array('posts_per_page' => 10));
if($this_query->have_posts()):
while($this_query->have_posts()): $this_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
<?php endwhile;
wp_reset_postdata();
endif;
die();
}
index1.php in core WP folder Where actual error occur
<html>
<head>
<title>My Ajax Page</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
function myajax(){
$.post('/wordpress/wp-admin/admin-ajax.php', {'action':'my_action'}, function(response){
$(#datafetch).append(response);
});
}
</script>
</head>
<body>
<div id="datafetch">
<button onclick="myajax()">Click Here</button>
</div>
</body>
</html>
The error message in console is
index1.php:15 Uncaught ReferenceError: myajax is not defined
at HTMLButtonElement.onclick

Why my DataTable jQuery cant load on my table view?

This is the code for the script,
but it's not working please help me.
<script>
function loading(){
$("#loading").removeAttr("hidden");
}
$(function () {
//Initialize Select2 Elements
$(".select2").select2();
$("#example1").DataTable();
});
</script>
This is the code for the script, but its not working please help me.
<script src="<?php echo base_url()?>public/jquery-1.12.3.min.js"></script>
<script src="<?php echo base_url()?>public/bootstrap/js/bootstrap.min.js"></script>
<script src="<?php echo base_url()?>public/app.min.js"></script>
<!-- DataTables -->
<script src="<?php echo base_url()?>public/datatables/jquery.dataTables.min.js"></sc‌ript>
<script src="<?php echo base_url()?>public/datatables/dataTables.bootstrap.min.js"><‌​/script>
<!-- Select2 -->
<script src="<?php echo base_url()?>public/plugins/select2/select2.full.min.js"></sc‌​ript>
this image is the console error please click here
I Fix it on my Own..
I have a "colspan= 2" in the view table and i have a extra "td" in my code thanks to all your comment.

How automatically refresh only one module in joomla?

How automatically refresh only one module in joomla?
<?php if ($this->countModules('parite')) : ?>
<section id="parite" >
<jdoc:include type="modules" name="parite" style="xhtml" />
</section>
<?php endif; ?>
That was the answer I was looking for.
<script type="text/javascript" src="https://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
var refreshId = setInterval(function()
{
jQuery('#parite').load('<?php echo $this->baseurl ?>/modules/mod_parite/mod_parite.php');
}, 1000);
</script>
<div id="parite"></div>

JQuery function is not called in PHP CodeIgniter

Iam new in php. I am trying to popup login window on click.but it is not working
This is my header_view
<head>
<script type="text/javascript" language="javascript" src="<?php echo base_url();?>Assets/js/popuplogin.js"></script>
<script type="text/javascript" language="javascript" src="<?php echo base_url();?>Assets/js/jquery.min.js"></script>
</head>
<body>
<div id="rightcorner">
<a href="#" id="loginlink" >Log In</a>
</div>
</body>
I included the below code in home.php(controller)
$this->load->library('javascript');
$this->load->library('javascript/jquery');
$this->load->helper(array('form'));
$data['library_src'] = $this->jquery->script();
$data['script_head'] = $this->jquery->_compile();
below is my popuplogin.js
$(document).ready(function() {
$("#loginlink").click(function(){
$("#logindiv").css("display","block");
});
When I click on loginlink nothing happened.
Pls help me.

$_SESSION breaks parameters in url (in Angular project)

We've built a small project prototype for a client, which needs to be password protected because of our NDA. However - our use of the $_SESSION variable seems to break the parameters provided when entering from a secondary source even if we're logged in.
This is what we want to happen:
www.externalsite.com -> oursite.com/#/route?param="value"
This is what happens:
externalsite.com -> oursite.com/#/route?param="value" -> oursite.com/#/defaultRoute
It would be awesome if anyone could tell me how to progress past this issue - either by providing actual solution or by linking to resources that might help or get us pointed in the right direction.
Here's our index.php
!doctype html>
<html>
<head>
<title>prototype</title>
</head>
<body ng-app="angularApp" ng-controller="mainCtrl">
<?php require('access.php'); ?>
<div class="wrap">
<!-- CONTENT -->
</div>
</body>
</html>
access.php:
<?php
$password = '43844e5d424a5c7d228f265f8c899d47a65cf52f';
session_start();
if (!isset($_SESSION['loggedIn'])) {
$_SESSION['loggedIn'] = false;
}
if (isset($_POST['password'])) {
if (sha1($_POST['password']) == $password) {
$_SESSION['loggedIn'] = true;
} else {
die ('Incorrect password');
}
}
if (!$_SESSION['loggedIn']): ?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form method="post">
<div class="form-group">
<label for="passwordInput">Password</label>
<input type="password" name="password">
</div>
<input type="submit" value="Login">
</form>
</body>
</html>
<?php
exit();
endif;
?>
The session_start() function must be the very first thing in your document. Before any HTML tags. You need to move it to index.php:
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<title>prototype</title>
</head>
<body ng-app="angularApp" ng-controller="mainCtrl">
<?php require('access.php'); ?>
<div class="wrap">
<!-- CONTENT -->
</div>
</body>
</html>

Categories