I have a mobile site where I am using JavaScript to refresh a message counter, JavaScript is enabled but it does not update the counter. The phone I am testing on is a Nokia e90. the other test phone is an HTC innovation and it works perfect on there.
Is it a issue of the JavaScript version on the e90 is out of date?
Here is my JS:
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo TITLE_HOME;?></title>
<meta http-equiv="content-language" content="en" />
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="include/js/jquery-1.3.2.min.js"></script>
<!-- like this-->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0b2.min.css" />
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0b2.min.js"></script>
<script>
$(document).ready(function()
{
refresh();
});
function refresh()
{
$.get('newMessageCnt.php', function (cnt) {
$("#msgcntDiv").html("You have " + cnt);
//console.log(cnt);
//$("#msgcntDiv").text("You have " + cnt);
window.setTimeout(refresh,30000);
});
}
</script>
and the php:
<?php
if ($numOfMessages <> 0)
{
echo "<span class='headings_sub' id='msgcntDiv'>You have " .$numOfMessages . "</span>";
echo "<a class='red_link' href='".ADDRESS."messages.php'> unopened Messages</a>";
}
else
{
echo "<span class='headings_sub'>You have no new messages</span>";
}
?>
on the HTC $numOfMessages updates without a blink. On the E90 nothing happens
Try and add the id to the else echo statement
else {
echo "<span class='headings_sub' id='msgcntDiv'>You have no new messages</span>";
}
If you start with 0 messages then if other messages come you won't have a span id to update the text.
Symbian s60v3 navigator is based in webkit engine and javascript engine also.
Not sure to be the root cause of your problem. Give us your code, it can help.
Related
I'm new to JS and i want to receive the value from a variable in JS, send it by post (or ajax) to a PHP file, and see the text display. The thing is i've been trying different ways to do it but i always get a undefined index in php.
My code is below
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>PRUEBA AJAX JS PHP HTML</title>
</head>
<body>
<H1>prueba</H1>
<input type="checkbox" name="switch" id="switch" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$("#switch").change(function ()
{
var checked=$("#switch").attr("checked");
if(checked)
{
$("switch").removeAttr("checked");
console.log("estado apagado switch 1");
var estados="1";
$.post("accion.php", {estado: "david"});
}else
{
$("#switch").attr("checked","checked");
console.log("estado encendido switch 1");
var estados="2";
$.post("accion.php", {estado: "david 2"});
}
});
</script>
</body>
</html>
accion.php
<?php
$est = $_POST['estado'];
echo $est;
if ($est=="david") {
echo "no mameees";
}else{
echo "no mameees no se puso ";
}
?>
Someone has any idea ?
$("#switch").change(function () {
var checked=$("#switch").prop("checked");
if(checked)
{
console.log(checked);
}else{
console.log(checked);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Switch <input type="checkbox" name="switch" id="switch" >
Use prop instead of attr to find checkbox is checked or not.
You can let php check if the checkbox was checked or not in a success callback from $.post:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>PRUEBA AJAX JS PHP HTML</title>
</head>
<body>
<H1>prueba</H1>
<input type="checkbox" name="switch" id="switch" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$("#switch").change(function ()
{
var checkbox = $("#switch");
$.post("accion.php", {estado: checkbox.val()}, function(data){
$("h1").html(data);
});
});
</script>
</body>
</html>
accion.php
<?php
$checkbox = isset($_POST['estado']) && $_POST['estado'] == 'on'; // 'on' is the default checkbox value when you don't specify it in html
if ($checkbox) {
echo "it's been checked";
}else{
echo "it wasn't checked";
}
?>
PS: when working with ajax ( check out $.post options) i recommend using dataType: 'json' and your php should respond with a valid JSON, you have json_encode for that.
use
var checked = $('#switch').is(':checked');
instead of
var checked=$("#switch").attr("checked");
i need a little info on google recaptcha. I want to grab the value of "g-recaptcha-response" that compares in the captcha.php file i inserted below in my jquery file and then send it to the captcha.php file using jquery $.post() method. I apologize if this is duplicate but i really cannot find someone with my same problem ;)
THE HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="AlterVista - Editor HTML"/>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="handle_spam.js" type="text/javascript"></script>
<title></title>
</head>
<body>
<div class="g-recaptcha" data-sitekey="6Lf8LxIUAAAAALg93pw24l53KTeqrIwl7kUY-opk"></div>
<button id="go">Register</button>
</body>
</html>
THE PHP
<?php
$captcha=$_POST['g-recaptcha-response'];
echo $captcha;
if(!$captcha){
echo 'You must verify yourself';
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Lf8LxIUAAAAACB9iqeOermR-rPOW0zcWRfoetBO&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false)
{
echo 'abort_all';
}else
{
echo 'success';
}
?>
THE JS
$(document).ready(function(){
$('#go').click(function(){
send=$('')
$.post('captcha.php',function(data){
alert(data);
});
});
});
Use this
<div class="g-recaptcha" data-callback="captchaCallback" data-sitekey="...">
and provide the function:
function captchaCallback(response) {
alert(response);
}
I installed Apache2 server on linux Mint system to do some web development. I have a code where there is a text in <pre> tag. The php code makes a link to edit the text by transferring all text into edit page <textarea>.
The text transfers in URI. Well, as Apache has a URI length limit, I don't know how to transfer large amount of text.
I searched and found out that there is a way to change this limit, but I couldn't find out where it is set. Also I read that it is not good to use long URIs.
So, I have to either increase the URI length limit or change my code. I haven't figured out how, though. This is the piece of page where text is (story.php, stored in $s variable):
<!DOCTYPE html>
<?php session_start() ?>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="main.css">
<title>The story</title>
<style>
#story{border: darkolivegreen; border-style: solid ;border-width: 3px; padding: 10px }
pre{white-space: pre-wrap}
span{padding-right: 8px}
</style>
</head>
<body>
<?php
include "navigation.php";
$id=$_GET['id'];
//ar_dump($id);
$mysql=new mysqli("",databaseuser,databasepassword,database);
$set=$mysql->query("select title,story,creator,dateCreated,identifier from Stories where identifier='$id'");
if( $set==false) echo $mysql->error;
$record=$set->fetch_array();
//var_dump($record);
if($record)
{
$t=$record['title'];
//check
$s=htmlspecialchars_decode($record['story']);
$c=$record['creator'];
$time=$record['dateCreated'];
$storyid=$record['identifier'];
echo "<h1 id='heading'>$t</h1>";
echo "<h2>By $c on $time</h2>";
echo "<pre id='story' on>$s</pre>";
if(isset($_SESSION[username]))
$user=$_SESSION[username];
$q="SELECT class FROM Accounts WHERE identifier='$user'";
$result=$mysql->query($q);
$group;
if($res)
{
$group=$result->fetch_array()[0];
}
if(($user==$c && $group==users2) or $group==admins or $group==overseers)
{
$s=urlencode($s);
$link='editstory.php?sid='.$storyid.'&text='.$s;
echo "<a href='$link'>Edit</a>";
//echo "<button data-storyid='$storyid' data-story='$s' onclick=''>Edit</button> ";
echo "<button data-storyid='$storyid' onclick='deleteStory(this)'>Delete</button>";
}
This is the page where text transfers into (editstory.php):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Editing</title>
<link rel="stylesheet" href="main.css"
</head>
<body>
<?php
$storyid=$_GET['sid'];
$text=$_GET['text'];
$text=urldecode($text);
echo "<textarea id='text' rows='33' cols='200'>$text</textarea>
<button data-sid='$storyid' onclick='updatestory(this)'>Save</button>
"
?>
<script>
function updatestory(button) {
var sid=button.getAttribute('data-sid')
var text=document.getElementById('text')
var value=text.value;
console.log(text.value)
var request=new XMLHttpRequest()
request.onreadystatechange=function () {
if(request.readyState==4)
{
window.location='story.php?id='+sid;
console.log(request.responseText)
}
}
request.open('POST','updatestory.php',true)
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send('sid='+sid+'&text='+value)
}
</script>
</body>
</html>
There should be no reason to tamper with URI length.
You should instead send the story text data as HTTP POST message body, and the submission could be inside HTML form element.
See W3 PHP5 Form Handling
I couldn't figure out how to change my code, so I've increased URI length for now.
I am trying to implement search with auto suggestion in my script but unfortunately I am unable to understand why it is not giving values. I have created two files. One is HTML which has JavaScript functions and some HTML in to and the other one is PHP. Can you please help me to find out what problem is with the code which is not able to display records in the text box?
File: index.html
<!DOCTYPE html>
<script src="jquery-1.11.2.min.js"></script>
<script type="text/JavaScript">
function lookup(inputString){
if (inputString.length==0){
$('#suggestions').hide();
} else{
$.post("suggestions.php",{
queryString: "" + inputString + ""},
function(data){
$('#suggestions').html(data).show();
});
}
}
</script>
<html>
<form>
<input type="text" size="30" onkeyup="lookup(this.value);">
<div id="suggestions"></div>
</form>
<head lang="en">
<meta charset="UTF-8">
<title>Sandbox Page</title>
</head>
<body>
</body>
</html>
File: suggestions.php
<p id="searchresults"><?php
$db=new mysqli('localhost','root','','RateList');
if(isset($_POST['queryString'])){
$queryString=$db->real_escape_string($_POST['queryString']);
if(strlen($queryString)>0){
$query = $db->query("SELECT * FROM RateList.VoipRoutes" . $queryString);
if($query){
while ($result = $query ->fetch_object()){
echo '<a href="'.$result->name.'">';
$name=$result->name;
echo ''.$name.'';
}
}
}
}
?></p>
Your SQL query is malformed. If I type "kittens" into the text box, the SQL query will be:
SELECT * FROM RateList.VoipRouteskittens
I can't seem to figure out what I'm doing wrong with this no matter how many things I try. I've looked through Google for a related issue but found nothing specific. Hopefully someone can help me.
The script runs through a external .js file calling a list of music albums, then listing the song of the album chosen via ajax. The user can then edit of delete the songs. Everything works fine until I submit the edited information through a form. When I click the submit button I get a web developer error "updateSong is not a function"
Here's the form:
<?php
include("database.php");
$song = $_GET['song'];
$query = "SELECT * FROM song INNER JOIN genre ON song.gID = genre.gID INNER JOIN album ON song.alID = album.alID WHERE sID = '$song'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
echo ("
<form action='#' method='POST' name='updateSong' onSubmit='updateSong(\"$song\")'>
<input name='songName' type='text' value='$row[songName]' />
<input type='text' id='genreSearch' name='genre' alt='Genre Search' onkeyup='searchSuggest();' autocomplete='off' value='$row[genreName]'/>
<div id='genre_search_suggest'></div>
<input name='songURL' type='text' value='$row[songUrl]' />
<input name='sID' type='hidden' value='$row[sID]' />
<input name='Submit' type='Submit' value='Update Song' />
</form>
");
}
?>
Here's the javascript:
function updateSong(sID) {
if(ajax) {
var song = sID;
alert("2");
ajax.open('get', './song_update.php' + encodeURIComponent(sID));
alert("3");
ajax.onreadystatechange = function() {
handleResponse(ajax);
}
ajax.send(null);
return false;
}
}
//EDIT//
Here's the page it's loaded into. I removed the unnecessary stuff around what this question is dealing with.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="artistPageStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="javascripts/artistAjax.js"></script>
</head>
<body>
<div id="mediaPlayerBox">
<div id="artistAlbumList">
<?php
$query = "SELECT * FROM `album` INNER JOIN artist ON album.aID = artist.aID WHERE artist.LoginKey = '$token'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
echo ("<div id='artistAlbumBox'><div id='artistAlbum'><a href='#' onclick='loadAlbum($row[alID])'><img src='$row[albumCover]' width='75px' height='75px' border='0px' ></a></div><div id='artistAlbumLabel'>$row[albumName]</div></div>");
}
?>
</div>
</div>
</body>
</html>
Shouldn't it be: onSubmit='updateSong("$song")'?
try doing onSubmit='return updateSong($song)'
It's saying it is not a function because it isn't loaded, are you loading the external script in the display page at all?