riahc3 50 Â Team Colleague

I was alerting it; I did it the same way you did and used those exact lines as the first in the file and correct it shows:

sjqh7d8lhhl84tn35k95uvd7e7
IN COOKIE: PHPSESSID=sjqh7d8lhhl84tn35k95uvd7e7
IN URL: 

Ill implent now your previous post and get back to you....

riahc3 50 Â Team Colleague

And now what?

riahc3 50 Â Team Colleague

That prints out:

IN COOKIE: PHPSESSID=imoddsalej884u92d1scichlh1
IN URL: 
riahc3 50 Â Team Colleague

In "updatesession.php" what am I suppose to "echo" back??? Honestly it makes NO sense to me and I cannot "logically" establish the session variable because I have no idea what it does....

riahc3 50 Â Team Colleague

Any other hints/tips?

Now using that same code, it suddenly does not work.

riahc3 50 Â Team Colleague

I dont understand why it doesnt work.

riahc3 50 Â Team Colleague

Let me get some code up:

PHTML page:

<script type="text/javascript">
$j('#list').change(function() {
                    var variablecalle=$j("#listadetiendas").val();
                    alert ("i work");


                    var currentSessionID = "<?php echo session_id(); ?>";
                    var data='calle='+encodeURIComponent(variablecalle)+'&ses='+currentSessionID;



                    $j.ajax({
                            url: '../../updatesession.php',
                            async: false,
                            type: 'POST',
                            cache: false,
                            data: data
                            }).done(function(data){
                                alert ("cambio el valor " + data);

                            //append the recieved data on success


                            $j("#currSess").html(data);
                            $j("#currSess").html( $j("#currSess").text() );
                            var wrap = $j("#currSess");
                            var text = wrap.text();
                            wrap.replaceWith(text);

                            });
                });
</script>

updatesession.php

<?php


    session_start();
    require '../app/Mage.php';
    Mage::app();


    Mage::getSingleton('core/session', array('name' => 'frontend'));
    Mage::getSingleton('core/session')->setBest($_POST['calle']);



    $_SESSION['calle'] = $_POST['calle'];



?>

Then where I recieve the data (which is another page) I (strangly) have to put:

$calle=$_SESSION['calle'];

Using standard PHP session.....

The problem is now when I change what I selected in the dropdown list, it still passes the old value, not the new.

riahc3 50 Â Team Colleague

GOT it to work! :)

Just one problem; When I change the dropdown box to another value, the onchange events pops but it does not update the value.

What could be wrong?

riahc3 50 Â Team Colleague

PHP is server Side script and Javascript client-side.So You can't do this.But you can use AJAX to call a PHP function from Javascript.

Great :) How do I do this?

I currently have this:

PHTML:

 <script type="text/javascript">
 $j(document).ready(function() 
                {



                    var variablecalle=$j("#listadetiendas").val();


                    var currentSessionID = "<?php echo session_id(); ?>";
                    var data='calle='+encodeURIComponent(variablecalle)+'&ses='+currentSessionID;



                    $j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }).done(function(data){


                            $j("#currSess").html(data);
                            $j("#currSess").html( $j("#currSess").text() );
                            var wrap = $j("#currSess");
                            var text = wrap.text();
                            wrap.replaceWith(text);

                            });
                });
                </script>

Now here is the problem: I cant access that PHP object/function in a AJAX call.

updatesession.php:

<?php

    require 'C:/folder/app/Mage.php';
    Mage::app();
    Mage::getSingleton('core/session')->setTest($_POST['calle']);


?>

When I access the getter, it shows null. I think its because the PHP object isnt passed so how could I pass it (and later return it)?

riahc3 50 Â Team Colleague

There has to be some way to do this.

riahc3 50 Â Team Colleague

Hello

How can I do something like this:

<script type="text/javascript">
var one="hi ";
var three="there";
<?php echo ConcatTwoStrings(?>one<?php,?>two<?php);?>;
</script>

That should produce "Hi there". Yes, I know there is concat Javascript functions; Thats not the point as I was simply showing a easy example.

How can I do the above?

Thank you

riahc3 50 Â Team Colleague

Have you tried a fully qualified URL (starting with http://)?

Firebug finds it and if I change its name, it says its not found so no, Im not making the same mistake twice :)

How can I use that "Mage::getSingleton('core/session')->setTest()" PHP object/method in Javascript? Possibly AJAX related but Im not sure how to do it.

riahc3 50 Â Team Colleague

I have tried different things but no luck; Any ideas on how to do this?

riahc3 50 Â Team Colleague

Nope, it cannot access it.

riahc3 50 Â Team Colleague

Would it be possible to pass the "Mage::getSingleton('core/session')->setTest()" object/method so the AJAX page itself can modify it? The problem is that the ajax page cannot access it (I think)

riahc3 50 Â Team Colleague

We are gettting somewhere.....

That code above sends

?><div id="currSess"></div><?php

To the webservice.

riahc3 50 Â Team Colleague

OK I got a idea and no error :)

<?php Mage::getSingleton('core/session')->setTest('?><div id="currSess"></div><?php '); ?>


            <script type="text/javascript">



                $j(document).ready(function() 
                {




                    var variablecalle=$j("#listadetiendas").val();



                    var currentSessionID = "<?php echo session_id(); ?>";
                    var data='calle='+encodeURIComponent(variablecalle)+'&ses='+currentSessionID;
                    //var data = encodeURIComponent('calle='+variablecalle); <---------big difference between this and line before it


                    //var data = 'calle='+variablecalle;
                    $j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }).done(function(data){
                            //append the recieved data on success
                            $j("#currSess").html(data);
                            $j("#currSess").html( $j("#currSess").text() );
                            var wrap = $j("#currSess");
                            var text = wrap.text();
                            wrap.replaceWith(text);

                            });
                });
                </script>

Would this work??? Ill test it in a sec

riahc3 50 Â Team Colleague

Got a great idea! :) The problem is I dont know how to write it correctly.

This is pure PHP:

<?php Mage::getSingleton('core/session')->setTest('my test'); ?>

How can I do this:

<script type="text/javascript">



                $j(document).ready(function() 
                {




                    var variablecalle=$j("#listadetiendas").val();

                    <?php Mage::getSingleton('core/session')->setTest( ?>variablecalle <?php); ?>


                });
                </script>

It is EXACTLY what I need. I just dont know how to set it correctly. I can do something like

var currentSessionID = "<?php echo session_id(); ?>";

So I KNOW it works.

riahc3 50 Â Team Colleague

session.use_cookies is already to true.

Im thinking of ways to do what I want to do...

riahc3 50 Â Team Colleague

I did this:

PHTML:

<?php echo session_id(); ?>

                    start
                    <div id="currSess"></div>
                    finish
            <script type="text/javascript">



                $j(document).ready(function() 
                {
                    var variablecalle=$j("#listadetiendas").val();

                    var currentSessionID = "<?php echo session_id(); ?>";
                    var data='calle='+encodeURIComponent(variablecalle)+'&ses='+currentSessionID;
                    //var data = encodeURIComponent('calle='+variablecalle); <---------big difference between this and line before it


                    //var data = 'calle='+variablecalle;
                    $j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }).done(function(data){
                            //append the recieved data on success
                            $j("#currSess").html(data);
                            });
                });

Then in the PHP:

<?php
    /*session_start();
    $_SESSION['calle']=$_POST['calle'];
    $_SESSION['fecha']=$_POST['fecha'];*/


    /*session_start();
    //echo if the calle session do exists
    echo '{' . '"calleSet":' . (isset($_SESSION['calle'])?'true,':'false,')
    //echo the sessID
        . '"sessID":' . '"'. session_id() .'",'
    //resend the post value of calle
        . '"callePostVal":' . '"'. (isset($_POST['calle'])?$_POST['calle']:'') .'"}';*/


    session_id($_POST['ses']);
    session_start();
    $_SESSION['calle'] = $_POST['calle'];
    $f = new StdClass();
    $f->calleSet= isset($_SESSION['calle'])?true:false;
    $f->sessID = session_id();
    $f->callePostVal = isset($_POST['calle'])?$_POST['calle']:'';
    echo json_encode($f);


?>

And it works giving me the result of:

le9vare5h0jgvl49gdmueiffv4 empiezo
{"calleSet":true,"sessID":"le9vare5h0jgvl49gdmueiffv4","callePostVal":"Calle Pruebas"}
termino 

thats all fine but then in ANOTHER php page, I BELIEVE the id is again different because it doesnt work.

I tried doing this with cookies but I believe it gave me similar problems (some domain/path issue I believe it was). Also, HTML5's local storage gave me the same problems. I thought session variables were the way to go :(

Ill keep trying with this session variable.

riahc3 50 Â Team Colleague

Well it seems the session id in the PHTML page is different than the one in the PHP page; How can I make (aka force) them use the same session ID?

riahc3 50 Â Team Colleague

I think it has something to do with the session id you guys commented:

Put this code:

<?php echo session_id(); ?>

                    start
                    <div id="currSess"></div>
                    finish

                    /*JAVASCRIPT THAT DOES AJAX CALL BELOW*/

And it gave me this (This is the HTML source):

 ncjli2vcfqos4qne8soosi3h63 start
<div id="currSess">{"calleSet":true,"sessID":"gslqmj45ih6e6cdtg5koc8bol1","callePostVal":"Calle Pruebas"}</div>
finish

Where do I continue from here?

riahc3 50 Â Team Colleague

(insert 10000000000 curse words here)

I was editing the wrong updatesession.php Damn it. Sorry for wasting your time, guys.

Lets start from the top basically and Ill tell you what I current got. Once again, I apoligize.

PHTML:

start
                    <div id="currSess"></div>
                    finish
            <script type="text/javascript">



                $j(document).ready(function() 
                {
                    var variablecalle=$j("#listadetiendas").val();

                    //var currentSessionID = "<?php echo session_id(); ?>";
                    var data='calle='+encodeURIComponent(variablecalle);
                    //var data = encodeURIComponent('calle='+variablecalle); <---------big difference between this and line before it


                    //var data = 'calle='+variablecalle;
                    $j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }).done(function(data){
                            //append the recieved data on success
                            $j("#currSess").html(data);
                            });
                });
                </script>

PHP:

<?php
    /*session_start();
    $_SESSION['calle']=$_POST['calle'];
    $_SESSION['fecha']=$_POST['fecha'];*/


    /*session_start();
    //echo if the calle session do exists
    echo '{' . '"calleSet":' . (isset($_SESSION['calle'])?'true,':'false,')
    //echo the sessID
        . '"sessID":' . '"'. session_id() .'",'
    //resend the post value of calle
        . '"callePostVal":' . '"'. (isset($_POST['calle'])?$_POST['calle']:'') .'"}';*/


    session_start();
    $_SESSION['calle'] = $_POST['calle'];
    $f = new StdClass();
    $f->calleSet= isset($_SESSION['calle'])?true:false;
    $f->sessID = session_id();
    $f->callePostVal = isset($_POST['calle'])?$_POST['calle']:'';
    echo json_encode($f);


?>

This (in the div) gives the following result:

{"calleSet":true,"sessID":"gslqmj45ih6e6cdtg5koc8bol1","callePostVal":"Calle Pruebas"}

What I am intrested in is that "Calle Pruebas". There you have the session ID.

I think it works now....Thats what is looks like.

riahc3 50 Â Team Colleague

Still nothing. Odd.

PHTML:

                    start
                    <div id="currSess"></div>
                    finish
            <script type="text/javascript">



                $j(document).ready(function() 
                {
                    var variablecalle=$j("#listadetiendas").val();

                    //var currentSessionID = "<?php echo session_id(); ?>";
                    var data='calle='+encodeURIComponent(variablecalle);
                    //var data = encodeURIComponent('calle='+variablecalle); <---------big difference between this and line before it


                    //var data = 'calle='+variablecalle;
                    $j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }).done(function(data){
                            //append the recieved data on success
                            $j("#currSess").html(data);
                            });
                });
                </script>

PHP:

<?php
    /*session_start();
    $_SESSION['calle']=$_POST['calle'];
    $_SESSION['fecha']=$_POST['fecha'];*/


    /*session_start();
    //echo if the calle session do exists
    echo '{' . '"calleSet":' . (isset($_SESSION['calle'])?'true,':'false,')
    //echo the sessID
        . '"sessID":' . '"'. session_id() .'",'
    //resend the post value of calle
        . '"callePostVal":' . '"'. (isset($_POST['calle'])?$_POST['calle']:'') .'"}';*/


    session_start();
    $f = new StdClass();
    $f->calleSet= isset($_SESSION['calle'])?true:false;
    $f->sessID = session_id();
    $f->callePostVal = isset($_POST['calle'])?$_POST['calle']:'';
    echo json_encode($f);


?>

Im kinda of confused now :S

riahc3 50 Â Team Colleague

Thank you pritaeas and gon1387.

gon1387, Im going to adapt the code you posted to what I have....

Might take a minute or two.

riahc3 50 Â Team Colleague

New code:

 $j(document).ready(function() 
                {
                    var variablecalle=$j("#listadetiendas").val();

                    var currentSessionID = "<?php echo session_id(); ?>";
                    var data = encodeURIComponent('calle='+variablecalle);


                    //var data = 'calle='+variablecalle;
                    /*$j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }) */

                            $j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }).done(function(data){
                                $j(document.body).append("currSessID: |"+currentSessionID+"| data |"+data+"|");   
                                var retData = $j.parseJSON(data);
                                if(retData.sessID != currentSessionID){
                                alert("doesn't have an equal session id. \n current: " + currentSessionID + "\nIDinAjaxPage: " + retData.sessID);
                                }
                                if(!retData.calleSet){
                                alert("calle was not set. due to wrongid");
                                }
                                alert("sent calle: " + encodeURIComponent('calle='+variablecalle)+ "\nRecieved calle: " + retData.callePostVal);
                                });    
                });

Result:

currSessID: |3j5ncc0m9uggb34bisjdmogr96| data ||

riahc3 50 Â Team Colleague

Change that and now it gives me:

TypeError: retData is null

if(retData.sessID != currentSessionID)

riahc3 50 Â Team Colleague

Instead of building the JSON response with echo and string concatenation, I suggest building an array and using json_encode() on it.

What is the best/correct way to do this?

riahc3 50 Â Team Colleague

I actually have my cache disabled (using CacheToggle and browser.privatebrowsing.autostart=true) so its not the cache...

riahc3 50 Â Team Colleague

Also did a alert of variablecalle and it has a value.

riahc3 50 Â Team Colleague

I put a alert(data); before

var retData = JSON.parse(data);

And it returns nothing. Empty.

riahc3 50 Â Team Colleague

Same errror.

Here is the code again:

 $j(document).ready(function() 
                {
                    var variablecalle=$j("#listadetiendas").val();

                    var currentSessionID = "<?php echo session_id(); ?>";
                    var data = encodeURIComponent('calle='+variablecalle);


                    //var data = 'calle='+variablecalle;
                    /*$j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }) */

                            $j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }).done(function(data){
                                var retData = JSON.parse(data);
                                if(retData.sessID != currentSessionID){
                                alert("doesn't have an equal session id. \n current: " + currentSessionID + "\nIDinAjaxPage: " + retData.sessID);
                                }
                                if(!retData.calleSet){
                                alert("calle was not set. due to wrongid");
                                }
                                alert("sent calle: " + encodeURIComponent('calle='+variablecalle)+ "\nRecieved calle: " + retData.callePostVal);
                                });    
                });

PHP

<?php

    session_start();
    //echo if the calle session do exists
    echo '{' . '"calleSet":' . (isset($_SESSION['calle'])?'true,':'false,')
    //echo the sessID
        . '"sessID":' . '"'. session_id() .'",'
    //resend the post value of calle
        . '"callePostVal":' . '"'. (isset($_POST['calle'])?$_POST['calle']:'') .'"}';


?>
riahc3 50 Â Team Colleague

New code:

$j(document).ready(function() 
                {
                    var variablecalle=$j("#listadetiendas").val();

                    var currentSessionID = "<?php echo session_id(); ?>";
                    var data = encodeURIComponent('calle='+variablecalle);


                    //var data = 'calle='+variablecalle;
                    /*$j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }) */

                            $j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            }).done(function(data){
                                var retData = JSON.parse(data);
                                if(retData.sessID != currentSessionID){
                                alert("doesn't have an equal session id. \n current: " + currentSessionID + "\nIDinAjaxPage: " + retData.sessID);
                                }
                                if(!retData.calleSet){
                                alert("calle was not set. due to wrongid");
                                }
                                alert("sent calle: " + encodeURIComponent('calle='+variablecalle)+ "\nRecieved calle: " + retData.callePostVal);
                                });    
                });

PHP:

<?php
    session_start();
    echo ("post of calle ". $_POST['calle'] );
    echo ("session id is ". session_id());

?>

Firebug says:

SyntaxError: JSON.parse: unexpected end of data

var retData = JSON.parse(data);

riahc3 50 Â Team Colleague

Something is wrong with the PHP code so I put:

<?php



    session_start();
    echo ("post of calle ". $_POST['calle'] );
    echo ("session id is ". session_id());

?>
riahc3 50 Â Team Colleague

Im trying to set a session variable using AJAX but it doesnt seem to work:

This is my PHTML page:

<?php
session_start();
?>

//SOME CODE


            <script type="text/javascript">



                $j(document).ready(function() 
                {
                    var variablecalle=$j("#listadetiendas").val();



                    var data = 'calle='+variablecalle;
                    $j.ajax({
                            url: '../../updatesession.php',
                            type: 'POST',
                            data: data
                            })    

                });

Then this is my "updatesession.php" page:

<?php
    session_start();
    $_SESSION['calle']=$_POST['calle'];
?>
riahc3 50 Â Team Colleague

DaniWeb, the code behind it, the database, and all DaniWeb's content, is owned by DaniWeb LLC, of which I am the sole member. Of course, without members, the community would die. But that is no different than a small store where if they treat their customers terribly, the store will go out of business. That doesn't mean the store is owned by its customers.

That is the exact same point I was trying to make. I ment "made" as in made it grow.

Anyways that Firefox bug is odd....

riahc3 50 Â Team Colleague

32 or 64 bit?

Very odd.

riahc3 50 Â Team Colleague
riahc3 50 Â Team Colleague

Could the prototype library have something to do with this????

riahc3 50 Â Team Colleague

Yes they are, Dani owns DaniWeb. In USA "Free speech" laws applies to governments, not individual people. Read Dani's post again just one week ago. If she didn't have the right to limit speech on DaniWeb then her actions in that post would have been illegal.

Again no; The website, code, etc is all written by Daniweb's coding team. But the site itself, its content, its activity, etc is made by the members. Without them, it would die.

riahc3 50 Â Team Colleague

On IE9 it shows this.

Then I can confirm a bug on FF 18.0.1 on Windows 7. Does not appear for me.

riahc3 50 Â Team Colleague

You said you need a website with "chat,downloads,messages ect.". I think before even creating your site, you need to know what is your website going to transmit and who is your target audience.

Another thing: There are web programmers and web designers. VERY RARELY, one person is good at both. Web designers usually make a mockup in Photoshop and then web programmers reproduce it in code. This is one of the most complicated steps in making a pro website.

riahc3 50 Â Team Colleague

Again I click on Files and my browser automatically goes down (I imagine it makes a div unhidden and shows it) saying:

Upload Attachments

Files will automatically be attached to the post upon upload. Optionally, you can embed uploaded images within your post.

Nothing else.

riahc3 50 Â Team Colleague

The upload is triggered automatically after completing the browse.

Browse where/what/who/how?

riahc3 50 Â Team Colleague

I'd like to ask why <MICHAEL>'s last post was deleted. He expressed an opinion (a valid one if you ask me). It seems that the only reason it was deleted was out of fear of offending riahc3. There was no name calling. Every system has its foibles (or "personality" if you will). All problems are ranked on a scale from serious to not. The developers have some idea as to the effort required to fix each one. The effort is weighed against the annoyance factor and the perceived benefit. Then the problems are addressed in turn. This is how a business operates. If anyone finds that the existing problems are too annoying to live with then he/she is free to take their business elsewhere. As far as I can tell, that was the gist of <MICHAEL>'s post. I don't think it should have been deleted.

I completely agree. He was giving his opinion on myself and the thread without offending.

"free speech" is not an issue here, no one has the right to free speech on privately owned forums. The right to free speech is only a government issue, not private issue. If Dani said you will be banned for posting "IMO" then she ccan do that. The only reason foul language is banned is because Dani said so. I've been on other sites where it's perfectly acceptable language.

Forums are not made by the "privately owned", its made by its members. If the "privately owned" …

riahc3 50 Â Team Colleague

I went out of my way and searched for the code and found this:

<form action="http://www.daniweb.com/posts/js_upload_attachments" method="post" accept-charset="utf-8" id="attachment-uploader" target="attachment-iframe" class="user-input" enctype="multipart/form-data">

And where is that list/option/etc? NOWHERE. I apoligize if I miss it but searching thru the code its not anywhere I can see....

riahc3 50 Â Team Colleague

More great forum "features" on DaniWeb:

I like the "Files" button and this appears:

Upload Attachments

Files will automatically be attached to the post upon upload. Optionally, you can embed uploaded images within your post.

OK, that sounds good. Ill upload the file to my post.............Wait a minute: THERE IS NO UPLOAD BUTTON.

riahc3 50 Â Team Colleague

Hello

I have this drawing program on a canvas and when it is on the top left corner of the document, when I move the cursor over the canvas and it previews the point Im going to click it is perfect. But when I move the canvas (say 5 pixels) it dealigns.

Pictures:

http://img255.imageshack.us/img255/4800/worky.png
http://img838.imageshack.us/img838/3823/nowork.png

What could this be?

riahc3 50 Â Team Colleague

The exiting fullscreen doesnt work.

My two functions:

<script type="text/javascript">
function max()
{
    var docElm = document.documentElement;
        if (docElm.requestFullscreen) 
        {
            docElm.requestFullscreen();
        }
        else if (docElm.mozRequestFullScreen) 
        {
            docElm.mozRequestFullScreen();
        }
        else if (docElm.webkitRequestFullScreen) 
        {
            docElm.webkitRequestFullScreen();
        } 
        else if (docElm.msRequestFullScreen) 
        {
            docElm.msRequestFullScreen();
        } 
        else if (docElm.oRequestFullScreen) 
        {
            docElm.oRequestFullScreen();
        } 
        else
        {
            alert("I am 12 and what is this?");
        }
}

function min()
{

        if (document.fullScreen) 
        {
            document.cancelFullScreen();
        }
        else if (document.fullScreen) 
        {
            document.mozCancelFullScreen();
        }
        else if (document.fullScreen) 
        {
            document.webkitCancelFullScreen()
        }
        else if (document.fullScreen) 
        {
            document.msCancelFullScreen();
        } 
        else if (document.fullScreen) 
        {
            document.oCancelFullScreen();
        }  
        else
        {
            alert("I am 12 and what is this?");
        }
}





</script>

Unless Im missing something. Testing this in latest stable version of Firefox.

riahc3 50 Â Team Colleague

Without using HTML5 or something like Flash or Silverlight, I don't believe it is possible.

Nothing for IE9?