GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Ajax wizards in here (https://gfy.com/showthread.php?t=955156)

Jakez 02-22-2010 04:09 PM

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.

Quote:

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?

CunningStunt 02-22-2010 04:13 PM

http://upload.wikimedia.org/wikipedi...%282007%29.jpg

borked 02-22-2010 04:14 PM

jQuery man, jQuery ;)

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

Jakez 02-22-2010 04:15 PM

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.

digitaldivas 02-22-2010 05:25 PM

...or dreamweaver CS4, integrates ajax beautifully

fris 02-22-2010 09:55 PM

that sure is messy code compared to a few lines of jquery

Alky 02-22-2010 10:19 PM

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>


Azlord 02-22-2010 11:59 PM

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).

Jakez 02-23-2010 11:38 AM

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?

SmellyNose 02-23-2010 11:48 AM

jQuery is amazing - Use it immediately! :thumbsup

Get jQuery from jquery.com, don't include it from Google.

fris 02-23-2010 11:51 AM

Quote:

Originally Posted by Jakez (Post 16888038)
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.

BestXXXPorn 02-23-2010 11:54 AM

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.

Jakez 02-23-2010 12:04 PM

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.

Alky 02-23-2010 12:08 PM

Quote:

Originally Posted by Jakez (Post 16888133)
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.... :winkwink:

CS-Jay 02-23-2010 12:39 PM

Quote:

Originally Posted by Alky (Post 16888152)
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.... :winkwink:

I have to agree, Alky's code was way more sexy. Just use jquery, and be a happy camper.

Jakez 02-23-2010 12:48 PM

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
Quote:

function(keyPage, jsNum, aNum)
But no function name to reference? lol

Should I remove the .hide()'s and use something like
Quote:

$("form#theName").show();

fris 02-23-2010 01:01 PM

lookup .submit

seeandsee 02-23-2010 01:13 PM

Quote:

Originally Posted by CunningStunt (Post 16885183)

hehe where is he now ?!?

Jakez 02-23-2010 02:14 PM

Quote:

Originally Posted by seeandsee (Post 16888367)
hehe where is he now ?!?

Who the hell is that? Is it supposed to be some kind of jheri curl - jquery joke? lol

borked 02-23-2010 03:56 PM

Quote:

Originally Posted by Jakez (Post 16888262)
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.

borked 02-23-2010 03:58 PM

Quote:

Originally Posted by BestXXXPorn (Post 16888094)
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. :2 cents:

Jakez 02-24-2010 05:01 PM

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:
Quote:

<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:
Quote:

<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:
Quote:

<?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.

nation-x 02-24-2010 05:40 PM

You don't have to use json

Jakez 02-24-2010 05:46 PM

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!

nation-x 02-24-2010 05:52 PM

below is your function changed to return html
Code:

$.post("ajaxwork.php?a=import_videos", $("#target").serialize(),
  function(data){
    $("#ajaxCol"+jsNum).html(data);
  }, "html");

Quote:

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);

Jakez 02-24-2010 06:36 PM

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..

Jakez 02-24-2010 07:01 PM

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.

Jakez 02-24-2010 07:31 PM

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.

nation-x 02-24-2010 07:47 PM

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";
}
?>


nation-x 02-24-2010 07:58 PM

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

quantum-x 02-25-2010 02:47 AM

Quote:

Originally Posted by Jakez (Post 16892924)
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()

CunningStunt 02-25-2010 02:51 AM

Quote:

Originally Posted by seeandsee (Post 16888367)
hehe where is he now ?!?

"Considering his options" apparently (= burnt out and finished)

Bump for the code monkeys.

nation-x 02-25-2010 05:28 AM

Quote:

Originally Posted by quantum-x (Post 16893598)
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.

fris 02-25-2010 07:32 AM

now i know why babelogger is so horribly coded ;)

Jakez 02-25-2010 10:55 AM

Quote:

Originally Posted by nation-x (Post 16892957)
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.

nation-x 02-25-2010 12:26 PM

Quote:

Originally Posted by Jakez (Post 16894628)
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.


All times are GMT -7. The time now is 12:30 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123