Ajax wizards in here

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jakez
    Confirmed User
    • Jan 2004
    • 5656

    #1

    Ajax wizards in here

    Ok so I was using the GET method up until I realized I can't send paragraphs of textarea data, so I converted it to POST, but it's still cutting my paragraphs off??

    Sorry this doesn't paste well here.

    function readPage(keyPage, jsNum, aNum)
    {
    var pageContent;
    if(window.XMLHttpRequest)
    {
    pageContent = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
    pageContent = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
    alert("Browser doesn\'t support AJAX");
    }

    if(aNum==1)
    {
    var delimiter = document.getElementById('delimiter').value;
    var dump = document.getElementById('dump').value;
    var params = 'delimiter=' + delimiter + '&dump=' + dump;
    }
    pageContent.onreadystatechange = StateChange;
    pageContent.open('POST', keyPage, true);
    pageContent.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    pageContent.send(params);

    function StateChange()
    {
    var doLoading="<img src=ajax.gif>";
    if(pageContent.readyState==1 || pageContent.readyState==2 || pageContent.readyState==3)
    {
    document.getElementById('ajaxCol'+jsNum).innerHTML = doLoading;
    }
    if(pageContent.readyState==4)
    {
    document.getElementById('ajaxCol'+jsNum).innerHTML = pageContent.responseText;
    }
    }
    }
    Is something out of place or what?
    [email protected] - jakezdumb - 573689400

    Killuminati
  • CunningStunt
    Confirmed User
    • Aug 2006
    • 5594

    #2

    Comment

    • borked
      Totally Borked
      • Feb 2005
      • 6284

      #3
      jQuery man, jQuery ;)

      The sooner you start using it, the sooner the headaches disappear.

      For coding work - hit me up on andy // borkedcoder // com
      (consider figuring out the email as test #1)



      All models are wrong, but some are useful. George E.P. Box. p202

      Comment

      • Jakez
        Confirmed User
        • Jan 2004
        • 5656

        #4
        Son of a bitch.

        What's jquery got to do with this though? That shit looks way out of wack, like my headaches would disappear and migraines begin lol. I see a lot of people in google have found the solution by converting to POST, but mine isn't working.
        Last edited by Jakez; 02-22-2010, 02:29 PM.
        [email protected] - jakezdumb - 573689400

        Killuminati

        Comment

        • digitaldivas
          ..I Heart Cannibal Corpse
          • Sep 2007
          • 4328

          #5
          ...or dreamweaver CS4, integrates ajax beautifully
          ...

          Comment

          • fris
            Too lazy to set a custom title
            • Aug 2002
            • 55703

            #6
            that sure is messy code compared to a few lines of jquery
            Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

            Comment

            • Alky
              Confirmed User
              • Apr 2002
              • 5651

              #7
              Didn't test it at all... and you need to load the jquery libraries.
              Code:
              Jquery:
              
              <script type="text/javascript">
              	$("#isLoading").hide();
              	$(document).ready(
                      function(keyPage, jsNum, aNum) {
              		$("#isLoading").show();
                              $.post("/PHP_FILE_TO_CALL.php", { delimiter: $("#delimiter").val(), dump: $("#dump").val() },
                              function(response){
              			$("#ajaxCol"+jsNum).html(unescape(response));
                              });
              		$("#isLoading").hide();
                      });
                  };
              </script>
              
              Then just do like in the html:
              <span id="isLoading"><img src=ajax.gif></span>
              Last edited by Alky; 02-22-2010, 08:21 PM.

              Comment

              • Azlord
                Confirmed User
                • Dec 2003
                • 2651

                #8
                It's already been said and solved, but jq is the way to go forsure. There are some nice new ajax features in the newest version (1.4).

                Comment

                • Jakez
                  Confirmed User
                  • Jan 2004
                  • 5656

                  #9
                  Best. Forum. Evar.

                  Is it safe to load the libraries from Google? Hopefully they aren't changing the paths any time soon..

                  Edit: fuck, need your own API key to load from Google? This jquery shit is looking to be too much of a hassle, if other people are going to be using this then they're going to have to have these libraries installed and shit? Do most servers have this already?
                  Last edited by Jakez; 02-23-2010, 09:45 AM.
                  [email protected] - jakezdumb - 573689400

                  Killuminati

                  Comment

                  • SmellyNose
                    Confirmed User
                    • Aug 2009
                    • 206

                    #10
                    jQuery is amazing - Use it immediately!

                    Get jQuery from jquery.com, don't include it from Google.
                    I'm a PHP developer - 594086663 - [email protected]

                    Comment

                    • fris
                      Too lazy to set a custom title
                      • Aug 2002
                      • 55703

                      #11
                      Originally posted by Jakez
                      Best. Forum. Evar.

                      Is it safe to load the libraries from Google? Hopefully they aren't changing the paths any time soon..

                      Edit: fuck, need your own API key to load from Google? This jquery shit is looking to be too much of a hassle, if other people are going to be using this then they're going to have to have these libraries installed and shit? Do most servers have this already?
                      you dont need an api key for jquery.

                      just direct link to the library, or direct link to it off of jquery.com

                      http://jet.li/twitter/

                      this is something i did that uses some jquery to load via search.
                      Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                      Comment

                      • BestXXXPorn
                        Confirmed User
                        • Jun 2009
                        • 2277

                        #12
                        Or Prototype :P I'm a big fan of being able to create classes... although I will admit jQuery is pulling ahead in the race. If jQuery UI wasn't so bloated I'd consider switching faster.
                        ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com

                        Comment

                        • Jakez
                          Confirmed User
                          • Jan 2004
                          • 5656

                          #13
                          I don't see any good reasons not to load from Google. People are most likely going to have it cached already..

                          This jQuery shit is fucking UGLY man.. why does it have to look like this wtf lol.
                          Last edited by Jakez; 02-23-2010, 10:05 AM.
                          [email protected] - jakezdumb - 573689400

                          Killuminati

                          Comment

                          • Alky
                            Confirmed User
                            • Apr 2002
                            • 5651

                            #14
                            Originally posted by Jakez
                            I don't see any good reasons not to load from Google. People are most likely going to have it cached already..

                            This jQuery shit is fucking UGLY man.. why does it have to look like this wtf lol.
                            one reason not to load it from google is you dont have to depend on them....

                            i think my code is way more sexy then what you originally posted....

                            Comment

                            • CS-Jay
                              Confirmed User
                              • Oct 2003
                              • 1794

                              #15
                              Originally posted by Alky
                              one reason not to load it from google is you dont have to depend on them....

                              i think my code is way more sexy then what you originally posted....
                              I have to agree, Alky's code was way more sexy. Just use jquery, and be a happy camper.
                              I do stuff - aIm CS_Jay_D

                              Comment

                              • Jakez
                                Confirmed User
                                • Jan 2004
                                • 5656

                                #16
                                Ok I'm reading a bunch of stuff trying to figure all this jQuery mess out. Even though most of the tutorials online expect you to know a ton of shit already, but first..

                                How do I even call what you gave me within my HTML form?
                                There's the
                                function(keyPage, jsNum, aNum)
                                But no function name to reference? lol

                                Should I remove the .hide()'s and use something like
                                $("form#theName").show();
                                Last edited by Jakez; 02-23-2010, 10:57 AM.
                                [email protected] - jakezdumb - 573689400

                                Killuminati

                                Comment

                                • fris
                                  Too lazy to set a custom title
                                  • Aug 2002
                                  • 55703

                                  #17
                                  lookup .submit
                                  Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                                  Comment

                                  • seeandsee
                                    Check SIG!
                                    • Mar 2006
                                    • 50945

                                    #18
                                    Originally posted by CunningStunt
                                    hehe where is he now ?!?
                                    BUY MY SIG - 50$/Year

                                    Contact here

                                    Comment

                                    • Jakez
                                      Confirmed User
                                      • Jan 2004
                                      • 5656

                                      #19
                                      Originally posted by seeandsee
                                      hehe where is he now ?!?
                                      Who the hell is that? Is it supposed to be some kind of jheri curl - jquery joke? lol
                                      [email protected] - jakezdumb - 573689400

                                      Killuminati

                                      Comment

                                      • borked
                                        Totally Borked
                                        • Feb 2005
                                        • 6284

                                        #20
                                        Originally posted by Jakez
                                        Ok I'm reading a bunch of stuff trying to figure all this jQuery mess out. Even though most of the tutorials online expect you to know a ton of shit already, but first..

                                        How do I even call what you gave me within my HTML form?
                                        There's the

                                        But no function name to reference? lol

                                        Should I remove the .hide()'s and use something like
                                        What is it exactly you're trying to do?

                                        If it's a form submit and the div is to show based on submit response, why not use jQuery thickbox. There's got to be one of those examples that fits your needs (scroll down to the last AJAX example)? And damn simple to boot.

                                        For coding work - hit me up on andy // borkedcoder // com
                                        (consider figuring out the email as test #1)



                                        All models are wrong, but some are useful. George E.P. Box. p202

                                        Comment

                                        • borked
                                          Totally Borked
                                          • Feb 2005
                                          • 6284

                                          #21
                                          Originally posted by BestXXXPorn
                                          Or Prototype :P I'm a big fan of being able to create classes... although I will admit jQuery is pulling ahead in the race. If jQuery UI wasn't so bloated I'd consider switching faster.
                                          I was Prototype all the way till around 10 months ago I stumbled on jQuery and was fully sold. Especially its ability to interact with PHP scripts via AJAX using JSON arrays is just heaven.

                                          For coding work - hit me up on andy // borkedcoder // com
                                          (consider figuring out the email as test #1)



                                          All models are wrong, but some are useful. George E.P. Box. p202

                                          Comment

                                          • Jakez
                                            Confirmed User
                                            • Jan 2004
                                            • 5656

                                            #22
                                            Ok I managed to get something extremely simplified so that even I can understand it and someone can hopefully understand what I'm trying to do lol. Only one problem I have. I want the jQuery to just display whatever the PHP sends back to it, instead of having to go through all the json crap and having the jQuery handle what gets shown. Ex (I use tabs so the indents are gone sry):

                                            The js/jquery:
                                            <script type="text/javascript">
                                            function readPage(keyPage, jsNum, aNum)
                                            {
                                            if(aNum==1)
                                            {
                                            $(document).ready(function()
                                            {
                                            $.post("ajaxwork.php?a=import_videos", $("#target").serialize(),
                                            function(data){$("#ajaxCol"+jsNum).html(data.delim iter);}, "json");
                                            });
                                            }
                                            }
                                            </script>
                                            The HTML:
                                            <form id="target" action="javascript:readPage('page.php?a=do_this', 1, 1);">
                                            Delimiter: <input name="delimiter" value="|" size=1><br>
                                            <input type=submit value="Next">
                                            </form>

                                            <div id="ajaxCol1" style="display:inline;"></div>
                                            And the PHP:
                                            <?php
                                            if($_GET['a']=="do_this")
                                            {
                                            $return_json = "{'delimiter':'".$_POST['delimiter']."'}";
                                            echo $return_json;
                                            }
                                            ?>
                                            Should I just change the:
                                            $return_json = "{'delimiter':'".$_POST['delimiter']."'}";

                                            and make it send all the HTML/etc I want to display? Like:
                                            $everything="<b>blah blah blah ".$_POST['delimiter']."</b>";
                                            $return_json = "{'everything':'$everything'}";

                                            Edit: it works^ I guess I will just do it that way, but idk if it's the wrong way or it doesn't matter or what. I just don't want to handle all the printing and HTML in jquery because it's really going to clutter a lot of shit up. And having to rename all the $_POST's is just stupid imo I don't really understand the whole json thing.
                                            Last edited by Jakez; 02-24-2010, 03:15 PM.
                                            [email protected] - jakezdumb - 573689400

                                            Killuminati

                                            Comment

                                            • nation-x
                                              Confirmed User
                                              • Mar 2004
                                              • 5370

                                              #23
                                              You don't have to use json
                                              Last edited by nation-x; 02-24-2010, 03:44 PM.

                                              Comment

                                              • Jakez
                                                Confirmed User
                                                • Jan 2004
                                                • 5656

                                                #24
                                                Ok I replaced the <input> field with a textarea and it won't print anything if I have more than 1 line of text inside the textarea... what the faaaaaaack!
                                                [email protected] - jakezdumb - 573689400

                                                Killuminati

                                                Comment

                                                • nation-x
                                                  Confirmed User
                                                  • Mar 2004
                                                  • 5370

                                                  #25
                                                  below is your function changed to return html
                                                  Code:
                                                  $.post("ajaxwork.php?a=import_videos", $("#target").serialize(),
                                                     function(data){
                                                       $("#ajaxCol"+jsNum).html(data);
                                                     }, "html");
                                                  Originally posted by Jakez
                                                  Ok I replaced the <input> field with a textarea and it won't print anything if I have more than 1 line of text inside the textarea... what the faaaaaaack!
                                                  try using
                                                  Code:
                                                  echo htmlentities($return_json);
                                                  Last edited by nation-x; 02-24-2010, 03:57 PM.

                                                  Comment

                                                  • Jakez
                                                    Confirmed User
                                                    • Jan 2004
                                                    • 5656

                                                    #26
                                                    Changing the json to html makes it show nothing, no matter what I try to pass to it..

                                                    Edit: json_encode() seems to do the trick.

                                                    Edit 2: Well I finally got it to work with the multiple textarea lines, but now I'm back to the original problem where ajax wouldn't POST a large paragraph of text, and this jquery is passing even less text through, this is ridiculous..
                                                    Last edited by Jakez; 02-24-2010, 04:47 PM.
                                                    [email protected] - jakezdumb - 573689400

                                                    Killuminati

                                                    Comment

                                                    • Jakez
                                                      Confirmed User
                                                      • Jan 2004
                                                      • 5656

                                                      #27
                                                      Ok it's only returning a limited amount of text because of ' (single quotes) within the text.

                                                      I already have json_encode(nl2br($_POST['text_dump'])) what else? htmlentities and htmlspecialchars aren't helping.
                                                      [email protected] - jakezdumb - 573689400

                                                      Killuminati

                                                      Comment

                                                      • Jakez
                                                        Confirmed User
                                                        • Jan 2004
                                                        • 5656

                                                        #28
                                                        Here we go
                                                        json_encode(nl2br(str_replace("'","& #39;",$_POST['text_dump'])))

                                                        I just wanted to be able to send an FLV dump of text via ajax and I had to go through all this crap lol.
                                                        [email protected] - jakezdumb - 573689400

                                                        Killuminati

                                                        Comment

                                                        • nation-x
                                                          Confirmed User
                                                          • Mar 2004
                                                          • 5370

                                                          #29
                                                          I made you an example...

                                                          http://lifestyleamateurs.com/test.php

                                                          this is the php script I am posting to.

                                                          Code:
                                                          <?php
                                                          
                                                          $galleries = preg_split("/\r?\n|\r/", $_POST['textarea']);
                                                          
                                                          foreach($galleries as $gallery) {
                                                          	list($url, $description) = explode('|', $gallery);
                                                          	echo "<a href='{$url}'>{$description}</a><br>\n";
                                                          }
                                                          ?>

                                                          Comment

                                                          • nation-x
                                                            Confirmed User
                                                            • Mar 2004
                                                            • 5370

                                                            #30
                                                            btw... if you are going to be working with Ajax I highly recommend firebug... it's really your best tool for debugging ajax calls.

                                                            Comment

                                                            • quantum-x
                                                              Confirmed User
                                                              • Feb 2002
                                                              • 6863

                                                              #31
                                                              Originally posted by Jakez
                                                              Here we go
                                                              json_encode(nl2br(str_replace("'","& #39;",$_POST['text_dump'])))

                                                              I just wanted to be able to send an FLV dump of text via ajax and I had to go through all this crap lol.
                                                              You shouldn't have to worry about that - that's an horrendous way to 'escape' text.
                                                              Your server doesn't have magic_quote or some abomination on does it ?

                                                              If you're looking to secure text for a database insert, mysql_real_escape_string()
                                                              PrettyInCash.com - BoozedGFs.com - TeenGFs.com - JizzGFs.com- MilfUploads.com -

                                                              Comment

                                                              • CunningStunt
                                                                Confirmed User
                                                                • Aug 2006
                                                                • 5594

                                                                #32
                                                                Originally posted by seeandsee
                                                                hehe where is he now ?!?
                                                                "Considering his options" apparently (= burnt out and finished)

                                                                Bump for the code monkeys.

                                                                Comment

                                                                • nation-x
                                                                  Confirmed User
                                                                  • Mar 2004
                                                                  • 5370

                                                                  #33
                                                                  Originally posted by quantum-x
                                                                  magic_quote or some abomination on does it ?
                                                                  thx for the laugh this morning I pee my pants over the fact that so many large hosts have magic_quotes_gpc enabled by default.

                                                                  Comment

                                                                  • fris
                                                                    Too lazy to set a custom title
                                                                    • Aug 2002
                                                                    • 55703

                                                                    #34
                                                                    now i know why babelogger is so horribly coded ;)
                                                                    Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                                                                    Comment

                                                                    • Jakez
                                                                      Confirmed User
                                                                      • Jan 2004
                                                                      • 5656

                                                                      #35
                                                                      Originally posted by nation-x
                                                                      I made you an example...

                                                                      http://lifestyleamateurs.com/test.php

                                                                      this is the php script I am posting to.

                                                                      Code:
                                                                      <?php
                                                                      
                                                                      $galleries = preg_split("/\r?\n|\r/", $_POST['textarea']);
                                                                      
                                                                      foreach($galleries as $gallery) {
                                                                      	list($url, $description) = explode('|', $gallery);
                                                                      	echo "<a href='{$url}'>{$description}</a><br>\n";
                                                                      }
                                                                      ?>
                                                                      THAT's what I'm talkin' about! lol. Using the html instead of json wasn't working before but the example you made is perfect.

                                                                      And yeah certifiedhosting did have magic quotes on, just turned it off. I also installed firebug a couple days ago but haven't restarted firefox yet since I have like 30 damn tabs open.

                                                                      Thanks a million, hopefully I won't have to come back here and 'bug' ya'll again lol.
                                                                      [email protected] - jakezdumb - 573689400

                                                                      Killuminati

                                                                      Comment

                                                                      • nation-x
                                                                        Confirmed User
                                                                        • Mar 2004
                                                                        • 5370

                                                                        #36
                                                                        Originally posted by Jakez
                                                                        THAT's what I'm talkin' about! lol. Using the html instead of json wasn't working before but the example you made is perfect.

                                                                        And yeah certifiedhosting did have magic quotes on, just turned it off. I also installed firebug a couple days ago but haven't restarted firefox yet since I have like 30 damn tabs open.

                                                                        Thanks a million, hopefully I won't have to come back here and 'bug' ya'll again lol.
                                                                        It's cool... I sent you an icq, btw.

                                                                        Comment

                                                                        Working...