Jquery clientscript not responding in yii [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I works on local but does not work on live server
Yii::app()->clientScript->registerScript('users', "
var user_id = $('#uId').val();
$.ajax({
url:'user/personalInfo'
,type:'get'
,dataType:'json'
,data:{id:user_id}
,success:function(data){
//append to popup window
}
});
");

Try using Yii::app()->createUrl('user/personalInfo') fro creating the url
Yii::app()->clientScript->registerScript('users', "
var user_id = $('#uId').val();
$.ajax({
url:'" . Yii::app()->createUrl('user/personalInfo') . "'
,type:'get'
,dataType:'json'
,data:{id:user_id}
,success:function(data){
//append to popup window
}
});

try by this way
Yii::app()->clientScript->registerScript('users', "
var use_id = $('#uId').val();
var url = window.location.href.split('/');
var base_url = url[0] + '//' + url[2] + '/';
$.ajax({
url:base_url + 'user/personalInfo'
,type:'get'
,dataType:'json'
,data:{id:user_id}
,success:function(data){
//append to popup window
}
});
");

Related

Display that User Current Location as the value of the Textbox [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have here a codes that displays the current location of the user, this codes is already working. My problem is how to put the id "#location" as the value for my textbox in html form so that the current location will put in a textbox form.
$(document).ready(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showLocation);
} else {
$('#location').html('Geolocation is not supported by this browser.');
}
});
function showLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$.ajax({
type:'POST',
url:'../geo/getLocation.php',
data:'latitude='+latitude+'&longitude='+longitude,
success:function(msg){
if(msg){
$("#location").html(msg);
}else{
$("#location").html('Not Available');
}
}
});
}
HTML:
Location: <input id="location" type="text" value="" size="50">
<br>
If the ajax request works correctly (we don't know what kind of data it returns), when the problem is in wrong choice of method.
Use .val() instead of .html() because you can't insert html inside input.
if (msg) {
$("#location").val(msg);
} else {
$("#location").val('Not Available');
}

How to send an id broughted by json from ajax to a php post [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have this ajax to show a html table, the thing is, i have a method on viewmap.php to show the ubication depending the id you clicked at the table, but i need to send the uid to viewmap.php so the php can search it at the database, and i don't extactly know how to do that
$.ajax({
type: "GET",
url: "editinplace.php?tabla=1"
})
//Vector
.done(function(json)
{
json = $.parseJSON(json)
for(var i=0;i<json.length;i++)
{
$('.editinplace').append
(
"<tr><td class='id' value='uid'>"
+json[i].uid
+"</td><td>"
+json[i].name
+"</td><td>"
+json[i].ape
+"</td><td>"
+json[i].phone
+"</span></td><td class='editable' data-campo='status'><span>"
+json[i].status
+"</span><td>"
+"<a href='viewmap.php?uid=$uid'>View on map</a>"
+"</td>"
);
}
//
});
Is it not the uid you have from your json array?
"<a href='viewmap.php?uid="+json[i].uid+"'>View on map</a>"
If you want to pull it from php, you'd echo it like this
$.ajax({
type: "GET",
url: "editinplace.php?tabla=1"
})
//Vector
.done(function(json)
{
json = $.parseJSON(json)
for(var i=0;i<json.length;i++)
{
var uid = "<?php echo $uid; ?>";
$('.editinplace').append
(
"<tr><td class='id' value='uid'>"
+json[i].uid
+"</td><td>"
+json[i].name
+"</td><td>"
+json[i].ape
+"</td><td>"
+json[i].phone
+"</span></td><td class='editable' data-campo='status'><span>"
+json[i].status
+"</span><td>"
+"<a href='viewmap.php?uid="+uid+"'>View on map</a>"
+"</td>"
);
}
//
});
If you have shorthand PHP echo tags turned on, its simply -
"<a href='viewmap.php?uid=<?= $uid ?>'>View on map</a>"#
Otherwise its like this with full tags -
"<a href='viewmap.php?uid=<?php echo($uid); ?>'>View on map</a>"#

Sending form using jQuery [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm trying to send a form using jQuery and it's not working. This code with a <a> tag works fine, but inside a form using the submit button doesn't.
$('#send-comment').click(function(){
var id_parent = $('#id_parent').val();
var comment_text = $('#comment-box').val();
var user_id = <?php echo $_SESSION['log_id']; ?>;
var new_id = <?php echo $id_new; ?>;
$.post( "dn-functions.php", { func: "registerComment", id_parent: id_parent, comment_text: comment_text, user_id: user_id, new_id: new_id })
.done(function( data ) {
alert( data );
});
});
Do you know what am I doing wrong?
$('#send-comment').click(function(e){
e.preventDefault();
var id_parent = $('#id_parent').val();
var comment_text = $('#comment-box').val();
var user_id = <?php echo $_SESSION['log_id']; ?>;
var new_id = <?php echo $id_new; ?>;
$.post( "dn-functions.php", { func: "registerComment", id_parent: id_parent, comment_text: comment_text, user_id: user_id, new_id: new_id })
.done(function( data ) {
alert( data );
});
});
I'm pretty sure you are submitting the form and your request is not being sent since you're leaving the page on form submit.
So pass the event and prevent the default action of form submit.

Autonumber in inputting new records [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My patient number(pnum) need to have a autonumber, like BLHC-2014-0001. I need to automatically have the BLHC-current year-and auto increment of the number with 4 digits when i input new record.
function autonum(){
var c ='BLHC-2014-0001';
var d = c.split("-");
var e = d[2];
var f = parseInt(e,10);
var g = f+1;
var str = '' + g;
var pad = "0000";
var resu = str.length < 4 ? (pad+str).slice(-4) : str;
var lt = d[0]+'-'+d[1]+'-'+resu;
document.getElementById("pnum").value =lt;
}

loading items when user scroll down [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a database which has about 5000 books. When user comes on the page, I don't want to load the books by using simple select * from BOOkTABLE, my approach is to go as the user needs it, so I want that as the user scrolls down I could fetch data from the Database. May be in chunks of 15-20 books, is that a good approach? Any alternative?
Secondly I have alphabets on top of div so if a user clicks on "Z" we could fetch the books starting with Z and show him in the DIV.
Yes you can do this by using Ajax on scroll down.Something like that:
$(window).scroll(function () {
if ($(window).height() + $(window).scrollTop() == $(document).height()) {
$.ajax({
type: "POST",
url: 'abc.php',
async:false,
data:"pagedata="+pageData ,
cache: false,
success: function(data){
}
});
}
});
In abc.php you can set the query according to your requirement and render the html(response) to be shown when scrolled down.
For the first question, using ScrollTop() you can load iterations of data from your PHP after an interval of pixels has been scrolled.
You will need a PHP file, and JavaScript.
This is written freehand with no testing so I can't guarantee these will work, but try something along these lines:
JavaScript
jQuery(document).ready(function($){
// Set the number of pixels from the top you want the event to fire
// Select the number of books you would like to load each time
// i = number of loads you've called
var reloadAfter = 500;
var numberBooks = 20;
var i = 1;
$(window).scroll(function() {
if ( $(this).scrollTop() >= reloadAfter )
{
$.get("getbooks.php", {number:numberBooks , counter:i} )
.done(function(data){
$('#books').append("Title:", data.title)
.append("Author:", data.author);
});
reloadAfter = reloadAfter + reloadAfter;
i++;
}
});
PHP
$numberBooks = $_GET['number'];
$i = $_GET['counter'];
$upper = ( $numberBooks * $i );
$lower = ( $upper - $numberBooks );
$get_books = mysql_query('SELECT * FROM BOOkTABLE WHERE id > $lower AND id < $upper');
echo json_encode($get_books);

Categories