I am new to web development, and have encountered a problem with jquery and php. Having trouble calling a php file with jquery through xampp using a simple GET and POST a http request. Any help would be greatly appreciated. Thank you!
<?php
$name=$_POST['name'];
if($_POST['name']!=""){
echo 'Shalom'.$name;
}else{
echo 'Enter name';
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<input type="text" id="name" placeholder="Name"/>
<button id="button">Submit</button>
<div class="response"></div>
<script type="text/javascript">
$('#button').click(function(){
var name=$('#name').val();
$.post('jquery post http request.php',{name:name},function(response,status,xhr){
$('.response').text(response);
});
});
</script>
</body>
</html>
Related
Hi I had used TinyMCE in my code single page code to upload data into server using TinyMCE. My Code is as follows, this is the add.php page :
<?php
$msg="";
include("config.php");
if($_POST['title']!= ""){
$title= $_POST['title'];
$words= $_POST['words'];
$words= stripslashes($words);
if (!$title)
{
$msg="Please Enter Title";
} elseif (!$words)
{
$msg="Please enter the Blog";
}
$query= mysql_query("INSERT INTO editor (title, content) VALUES ($title, $words)") or die (mysql_error());
$msg="Success!";
}
?>
<! DOCTYPE html>
<html>
<head>
<title>Add New Blog</title>
<script type="text/javascript" src="jquery-1.11.0"></script>
<script type="text/javascript" src="tinymce.min"></script>
<script type="text/javascript" src="jquery.tinymce.min"></script>
</head>
<body>
<div>
<p><b>Add a New Blog</b></p>
<form action="add.php" method="post">
Title of the Blog :
<br/>
<input type="text" name="title"></input>
<br/>
Your Blog :
<br/>
<textarea name="words" class="tinymce" cols="30" rows="10"></textarea>
<br/>
<input type="submit" value="submit"/> <?php echo $msg; ?>
</form>
</div>
</body>
</html>
My Textarea is displayed as a normal textarea, the data is also not going into the Database.
The config.php file is for Database connection and it is working fine, I checked it.
Please help, Thanks in advance.
<! DOCTYPE html>
<html>
<head>
<title>Add New Blog</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="http://tinymce.cachefly.net/4.0/tinymce.min.js"></script>
<script>
tinymce.init({
selector: "textarea"
});
</script>
</head>
<body>
<div>
<p><b>Add a New Blog</b></p>
<form action="add.php" method="post">
Title of the Blog :
<br/>
<input type="text" name="title"></input>
<br/>
Your Blog :
<br/>
<textarea name="words" class="tinymce" cols="30" rows="10"></textarea>
<br/>
<input type="submit" value="submit"/> <?php echo $msg; ?>
</form>
</div>
</body>
</html>
You forgot to add extension in linked script file
<script type="text/javascript" src="jquery-1.11.0.js"></script>
<script type="text/javascript" src="tinymce.min.js"></script>
<script type="text/javascript" src="jquery.tinymce.min.js"></script>
Check this Sample Demo
I think you are added two TinyMCE library so it's may be conflict problem. So please update only this two library
I am add only 2 library
JQuery Library - http://code.jquery.com/jquery-1.11.0.min.js
TinyMCE Library - http://tinymce.cachefly.net/4.0/tinymce.min.js
And In your Header add this script
<script>
tinymce.init({
selector: "textarea"
});
</script>
try now its work.
Folks,
I am new to js and this I am having trouble capturing and taking a screenshot of a remote website. Can someone point me in the right direction
I keep getting this error:
Uncaught TypeError: Object [object Object] has no method 'html2canvas' index.php:4201
capture index.php:4201
onclick
My code is index.php
<html>
<head>
<title>Hawk-Eye: Have a look at what others are upto</title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://localhost/Hawk-eye/html2canvas.js"></script>
<script type="text/javascript" src="http://localhost/Hawk- eye/jquery.plugin.html2canvas.js"></script>
</head>
<body>
<div id="target">
<?php
$homepage= file_get_contents('http://www.yahoo.com');
echo $homepage;
?>
</div>
<form method="POST" enctype="multipart/form-data" action="save.php" id="myForm">
<input type="hidden" name="img_val" id="img_val" value="" />
</form>
<script type="text/javascript">
function capture() {
$('#target').html2canvas({
onrendered: function (canvas) {
//Set hidden field's value to image data (base-64 string)
$('#img_val').val(canvas.toDataURL("image/png"));
//Submit the form manually
document.getElementById("myForm").submit();
}
});
}
</script>
<input type="submit" value="Take Screenshot" onclick="capture();" />
</body>
</html>
Download html4canvas and import it as
<script type="text/javascript" src="html2canvas.js?rev032"></script>
I am new in jQuery and need help to figure out why $.get does not reply.
Let me explain what I have: There is a main index.php as follows:
<!DOCTYPE html>
<html lang="en">
<head> <meta charset="utf-8"> </head>
<body>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/reqhan.js"> </script>
<input id="string" type="text" />
<input id="button" type= "button" value="Go" />
<div id="div"></div>
</body>
</html>
the js/reqhan.js contains
$(document).ready(function(e) {
alert('1');
$('#button').click(function() {
$.get('php/reverse.php',{input: string},function(data){alert('2');});
$('#div').text(data);
alert('3');
});
});
and reverse.php contains a simple code (I pasted here but does not preview it) that gets the text from reqhan.js file and returns an echo message.
when running the code on Google Chrome, the first alert is shown but not the rest and of course the `$('#div').text(data);' doesn't send back the data to the js file.
Please let me know if further info is required.
many thanks.
You're closing your callback function before you do anything with the data
Try this instead:
$(document).ready(function(e) {
alert('1');
$('#button').click(function() {
$.get('php/reverse.php',{input: string},function(data){
alert('2');
$('#div').text(data);
alert('3');
});
});
});
Try to format your code so that each pair of brackets gets its own indentation. It should help catch small things like this.
I was following a tutorial to understand how AJAX/PHP works but i'm having an issue.
Let me start with the code.
escalationTest.php:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form>
<input type="text" id="name" placeholder="Enter Name.." /> <br>
<input type="text" id="age" placeholder="Enter Name.." />
<input type="button" value="Submit" onClick="post();" />
</form>
<div id="result"></div>
<script type="text/javascript">
function post()
{
var name= $('#name').val();
var age= $('#age').val();
$.post('escalation.php',{postname:name,postage:age},
function(data)
{
$('#result').html(data);
});
}
</script>
</body>
</html>
escalation.php:
<?php
echo "working";
?>
I've typed the code exactly how its in the tut. From its output when i click the submit button i should "working" in the result div which is not happening.
What am i doing wrong here..?
Thanks.
<script type="text/javascript" src="jquery.min.js"></script>
Download a version of jQuery and then link to it with this script tag.
While you can link to an online version, it's not ideal for eventual production use and you should definitely get a local copy.
add the folowing line to your head tag
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
This is a pretty simple fix - you're missing jQuery. Add the following:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
in your head element.
I have a index.php file where I have canvas game. This game is loaded from separate game.js file where I have variable: ballsCought. I want this wariable and name inputet to text input pass on click to another php file. my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Simple Canvas Game</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
function score(){
$('#score').fadeIn(1000);
$('#score').load("load_players.php");
};
setInterval(score , 1000);
var nam = $("#name").val();
$('#submit').keyup(function(e){
if(e.keyCode == 13){
$.post('upload_score.php','n=' +nam, 'score=' +ballsCought);
}
});
$('#submit').click(function(e){
$.post('upload_score.php','n=' +nam, 'score=' +ballsCought);
});
});
</script>
</head>
<script src="game.js"></script>
<body>
<canvas id="canvas" width="525" height="525"></canvas>
<br /><p><span id="points"></span><input type="text" id="name" placeholder="Name..."/><input type="submit" id="submit" value="Submit"/></p>
<br /><span id="score"></span>
</body>
</html>
But this post function is not working any idea? THank you...
Looks like your $.post method is not correct. If you want to pass data to the PHP page you need to use the JavaScript object notation like so:
$.post('upload_score.php', {n: nam, score: ballsCought});
You can read more about the various ways to call $.post from the jQuery Docs page
Now there could still be problems with your PHP page. You should use something like Firebug to see the Ajax request and any errors that might be returned.