Be a Supporter!

Reducing the size of XHR?

  • 2,653 Views
  • 54 Replies
New Topic Respond to this Topic
uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Reducing the size of XHR? 2012-09-05 15:24:41 Reply

My XMLHttpRequest does take extremly long time to send. It sends 171 bytes of data in about 200-600ms. This is really wierd because I'm not actually retriving anything to the user... just sending the request to open a .php file to edit an MySQL database.

Possible causes:
1. I use GET and not POST. What is the right one here to use, btw?
2. I could minify the .php file?
3. My hosting company is giving me a slow bandwidth. (Even though I am paying for the most expensive one)
4. I use an URI to access the MySQL server and not an IP adress?

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Reducing the size of XHR? 2012-09-06 04:17:44 Reply

At 9/5/12 03:24 PM, uglybetty wrote: My XMLHttpRequest does take extremly long time to send. It sends 171 bytes of data in about 200-600ms. This is really wierd because I'm not actually retriving anything to the user... just sending the request to open a .php file to edit an MySQL database.

Possible causes:
1. I use GET and not POST. What is the right one here to use, btw?

no. If you are sending sensitive data use POST, though.

2. I could minify the .php file?

won't matter

3. My hosting company is giving me a slow bandwidth. (Even though I am paying for the most expensive one)

slow bandwidth impacts speed, of course

4. I use an URI to access the MySQL server and not an IP adress?

post the script?

In my opinion, the main reason you are having speed issues is you are sending too many headers. How many cookies have you set ? I suggest using CDN. It's really easy to make one. Google it.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Reducing the size of XHR? 2012-09-06 04:20:42 Reply

At 9/6/12 04:17 AM, NinoGrounds wrote: I suggest using CDN. It's really easy to make one. Google it.

Just to clarify a tad more. Put the file you are accessing via AJAX on a CDN network.
Example: http://portfolio.recgr.com/
I retrieve JSON from a sub - subdomain. It increased performance. By the way, it's a side I was working on, but I had to pause its development due to this paid job I got atm.

uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-06 09:04:04 Reply

4. I use an URI to access the MySQL server and not an IP adress?
post the script?

Here's the JavaScript:

var xmlHttp = getXMLHttp(); // XHR crossbrowser catch handler...
        var async = false;
        var counter = localcounter;
        localcounter = 0;
        xmlHttp.open("GET", "count.php?r=" + Math.random + "&count=" + counter, async);
        xmlHttp.send();

What I do, really, is just to send the value of localcounter into counter and then send it to the .php file.

$counter = $_GET['counter'];
mysql_connect("uritomyhost","myusername","password"); 
mysql_select_db('mydatabase');
mysql_query('UPDATE table SET field = field + ($counter)');
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Reducing the size of XHR? 2012-09-06 10:02:39 Reply

At 9/6/12 04:17 AM, NinoGrounds wrote:
1. I use GET and not POST. What is the right one here to use, btw?
no. If you are sending sensitive data use POST, though.

Using GET over POST is definitely not the issue, but Nino's suggestion to use POST isn't entirely accurate.
POST should be used if you are giving the server information in a non-specific manner. An example being a user posting in a shoutbox, or submitting a new support ticket; if you are taking user input and storing it on your server than use POST (or PUT, depending on the situation); if you are retrieving information from your server based on user input then use a GET request.

At 9/6/12 04:17 AM, NinoGrounds wrote: 4. I use an URI to access the MySQL server and not an IP adress?

An IP address is a URI. Using http://mysite.com/foo/somescript.php instead of http://123.42.11.42/foo/somescript.php won't make any difference, so this is not the issue.
I'm assuming that you meant URL, not URI, in which case the answer is the same: it won't make a difference.

At 9/6/12 04:17 AM, NinoGrounds wrote: $counter = $_GET['counter'];
mysql_connect("uritomyhost","myusername","password");
mysql_select_db('mydatabase');
mysql_query('UPDATE table SET field = field + ($counter)');

You really should be escaping that $counter variable; this script is highly susceptible to SQL injection.
Technically this should also be a PUT request, not a GET request, but I don't know how you'd do that in PHP; at the very least you should change this to a POST request (the difference between the two is explained here).

As for why your script is slow: it looks like it may just be caused by a slow server.
The only thing I can think of is to use Google Chrome to profile the AJAX request to see precisely where that delay is coming from (I am referring to Chrome's developer toolbar here; press F12 to open it up and go to the "network" tab and run your script; it will tell you detailed information regarding the request).

uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-06 12:13:46 Reply

You really should be escaping that $counter variable; this script is highly susceptible to SQL injection.
Technically this should also be a PUT request, not a GET request, but I don't know how you'd do that in PHP; at the very least you should change this to a POST request (the difference between the two is explained here).

So I should use POST in the JavaScript and the .php instead of GET? :) Also, what is wrong with using $counter? There's no other way because I have to actually hand over the value.

How about this: If I change the GET in the JavaScript to POST and get rid of the random function. GET is chaced and POST is not?

As for why your script is slow: it looks like it may just be caused by a slow server.
The only thing I can think of is to use Google Chrome to profile the AJAX request to see precisely where that delay is coming from (I am referring to Chrome's developer toolbar here; press F12 to open it up and go to the "network" tab and run your script; it will tell you detailed information regarding the request).

400ms the first time. About 250-270ms the rest :) The size of the request is 171 bytes.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Reducing the size of XHR? 2012-09-06 13:50:08 Reply

At 9/6/12 12:13 PM, uglybetty wrote: So I should use POST in the JavaScript and the .php instead of GET? :)

Correct.

Also, what is wrong with using $counter? There's no other way because I have to actually hand over the value.

I meant you should escape it, like this:

$counter = mysql_real_escape_string($_GET["counter"]);

or like this, if you're using a POST request:

$counter = mysql_real_escape_string($_POST["counter"]);

Note:
Even though escaping the value is a good idea that won't mean that you're 100% safe from SQL injection. You'll need to use a combination of prepared statements and escaping for that.

Double Note:
Make sure to use mysql_real_escape_string, and not just mysql_escape_string. The latter is broken and shouldn't be used.
It's poorly named, but whattya gonna do?

This is an excellent article on SQL injection. I recommend reading it. It goes into pretty thorough detail how someone with malicious intent can muck up your SQL database with simple injections.

How about this: If I change the GET in the JavaScript to POST and get rid of the random function. GET is chaced and POST is not?

Correct.
If you're using POST then the random function won't be necessary as your browser will never cache a POST request.

400ms the first time. About 250-270ms the rest :) The size of the request is 171 bytes.

If the request is under 1KB then its size really won't matter much, and 200-300ms is about what you'll always get for AJAX requests that are performed over WAN (a LAN request would yield around 3-10ms depending).
The original 400ms spike could have been caused by a lot of things; sometimes your requests get slowed down. C'est la vie.

uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-07 02:52:15 Reply

At 9/6/12 01:50 PM, Diki wrote:
At 9/6/12 12:13 PM, uglybetty wrote: So I should use POST in the JavaScript and the .php instead of GET? :)
Correct.

Thanks! I also noticed that in the request header, the random function was taking up a lot of space, too... so that will probably make the request a little faster

Also, what is wrong with using $counter? There's no other way because I have to actually hand over the value.
I meant you should escape it, like this:

$counter = mysql_real_escape_string($_GET["counter"]);

or like this, if you're using a POST request:

$counter = mysql_real_escape_string($_POST["counter"]);

Note:
Even though escaping the value is a good idea that won't mean that you're 100% safe from SQL injection. You'll need to use a combination of prepared statements and escaping for that.

Thanks. I never knew this. Pretty new here to PHP. For this, should I use MyISAM or InnoDB as a storage engine? I'm not quite sure, but this is counted as a small transtraction(s)?

Double Note:
Make sure to use mysql_real_escape_string, and not just mysql_escape_string. The latter is broken and shouldn't be used.
It's poorly named, but whattya gonna do?

This is an excellent article on SQL injection. I recommend reading it. It goes into pretty thorough detail how someone with malicious intent can muck up your SQL database with simple injections.

I'll have a look at it even though people are telling me not to use W3Schools :P

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Reducing the size of XHR? 2012-09-07 05:52:53 Reply

At 9/6/12 01:50 PM, Diki wrote: Note:
Even though escaping the value is a good idea that won't mean that you're 100% safe from SQL injection. You'll need to use a combination of prepared statements and escaping for that.

Since here's dealing with numerics ($counter is numeric) only, prepared statements are overkill. I mean, they are nice and all, but unnecessary for this purpose. I recommend using this:

if (is_numeric($counter)) {
// do the query
} else {
die("sql injection prevented.");
}
uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-07 08:07:44 Reply

Btw... I tried using $_POST in the PHP code when using POST in the JavaScript. This did not work. BUT when changing the PHP back to $_GET it did work. Wired, huh?

uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-07 08:27:05 Reply

At 9/7/12 08:07 AM, uglybetty wrote: Btw... I tried using $_POST in the PHP code when using POST in the JavaScript. This did not work. BUT when changing the PHP back to $_GET it did work. Wired, huh?

Also, this is how the request report looks like in Google Chrome:

Request URL:http://mysite.com/count.php?r=&count=1
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:nb-NO,nb;q=0.8,no;q=0.6,nn;q=0.4,en-US;q=0.2 ,en;q=0.2
Connection:keep-alive
Content-Length:0
Cookie:__utma=21548344.1009961159.1345404296.1346947616.1347 019306.19; __utmb=21548344.16.10.1347019306; __utmc=21548344; __utmz=21548344.1346604052.13.2.utmcsr=google|utmccn=(organi c)|utmcmd=organic|utmctr=(not%20provided)

User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
Query String Parametersview URL encoded
r:
count:1
Response Headersview source
Connection:close
Content-Length:1
Content-Type:text/html
Date:Fri, 07 Sep 2012 12:25:03 GMT
Server:Nginx / Varnish
X-Powered-By:PHP/5.2.17

The cookie header looks awfully big!

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Reducing the size of XHR? 2012-09-07 08:48:08 Reply

At 9/7/12 02:52 AM, uglybetty wrote: Thanks! I also noticed that in the request header, the random function was taking up a lot of space, too... so that will probably make the request a little faster

You probably won't notice the difference.
The random number you were generating was probably something like 10 digits long, or, in other words, using up approximately 10 bytes in the request, so the request will be a little bit faster, but the difference will be so tiny you won't notice.

At 9/7/12 02:52 AM, uglybetty wrote: Thanks. I never knew this. Pretty new here to PHP. For this, should I use MyISAM or InnoDB as a storage engine? I'm not quite sure, but this is counted as a small transtraction(s)?

That's actually not a PHP question; it's a MySQL question. :)
And using MyISAM or InnoDB depends on how you're going to be using the SQL table. Generally speaking you'll usually only need to use MyISAM, and if you're not sure then MyISAM is your safe bet.

This article does a good job of explaining the difference between the two engines.

Since you're still learning I'd say stick with MyISAM for now.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Reducing the size of XHR? 2012-09-07 08:53:24 Reply

At 9/7/12 08:07 AM, uglybetty wrote: Btw... I tried using $_POST in the PHP code when using POST in the JavaScript. This did not work. BUT when changing the PHP back to $_GET it did work. Wired, huh?

Are you still sending the GET variables in the URI?
Can you post what you changed your JavaScript code to?

At 9/7/12 05:52 AM, NinoGrounds wrote: Since here's dealing with numerics ($counter is numeric) only, prepared statements are overkill. I mean, they are nice and all, but unnecessary for this purpose. I recommend using this:

if (is_numeric($counter)) {
// do the query
} else {
die("sql injection prevented.");
}

The point was to teach him proper SQL security. As well, while that solution will work, it's an ad hoc.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Reducing the size of XHR? 2012-09-07 14:33:57 Reply

At 9/7/12 08:53 AM, Diki wrote: The point was to teach him proper SQL security.

Alrighty then

liljim
liljim
  • Member since: Dec. 16, 1999
  • Offline.
Forum Stats
Staff
Level 28
Blank Slate
Response to Reducing the size of XHR? 2012-09-07 14:36:33 Reply

I don't understand why there's parentheses around $counter - why are they there? And is there any reason why you're updating the whole table rather than just one row in it?

At 9/7/12 08:53 AM, Diki wrote: The point was to teach him proper SQL security. As well, while that solution will work, it's an ad hoc.

As much as that makes sense, if someone passes a string the query as he has it will still fail. He really should be checking whether the value is an integer or float.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Reducing the size of XHR? 2012-09-07 15:06:14 Reply

At 9/7/12 02:36 PM, liljim wrote: And is there any reason why you're updating the whole table rather than just one row in it?

Ahah, I didn't even notice that.
Yeah you probably want to stick a WHERE clause onto your query, otherwise it's going to update every single row in the table.

As much as that makes sense, if someone passes a string the query as he has it will still fail. He really should be checking whether the value is an integer or float.

That's true; I wasn't really thinking about it from that angle, so I guess since $counter should only ever be an integer (I'm assuming anyways) you could just do this:

$counter = (int)$_POST["counter"];
if ($counter > 0) {
    mysql_query('UPDATE table SET field = field + $counter');
}

Though that will still accept SQL injection attempts, such as the following:

$counter = (int)"42 WHERE 1=1; --"
if ($counter > 0) {
    mysql_query('UPDATE table SET field = field + $counter');
}

Which will convert the "42 WHERE 1=1; --" string to just 42, obviously, so it's technically safe from injection but still should be throwing some kind of an error over that input.
I suppose this would be a viable solution:

$counter = $_POST["counter"];
if ($counter === (string)(int)$counter) {
    mysql_query('UPDATE table SET field = field + $counter');
}

(this works but I felt dirty writing it)

Any non-base10-numerical characters, including ellipses, will be lost in the string->int->string conversion, so the comparison will fail if $_POST["counter"] is anything but an integer.
So Nino was right with his original conclusion that escaping or prepared statements are not really necessary in this esoteric situation.

uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-07 15:54:21 Reply

OK, Diki. I have tried everything with $_POST in PHP when using POST in JavaScript. It only works when using $_GET in the PHP. I can use either GET or POST in JavaScript, only $_GET works.

I have tried everything you have said here. The request url is http://mysite.com/count.php?r=&count=VALUESENTHERE

Sorry if sounding like you should do everything, but I have no experience using PHP, SQL and request...

To conclude: Everything works, but why this is happening, I don't have any clue. It might be that we use ?r= and not anything else?

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Reducing the size of XHR? 2012-09-07 16:02:05 Reply

At 9/7/12 03:54 PM, uglybetty wrote: The request url is http://mysite.com/count.php?r=&count=VALUESENTHERE

That's probably the problem. You only want to include the variables in the URI if you're making a GET request. Remove them and it should work.

To conclude: Everything works, but why this is happening, I don't have any clue. It might be that we use ?r= and not anything else?

Doing just r= is a valid GET variable definition; it will just assign nothing to the variable (in PHP it will end up being an empty string).

uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-07 17:04:01 Reply

At 9/7/12 04:02 PM, Diki wrote:
At 9/7/12 03:54 PM, uglybetty wrote: The request url is http://mysite.com/count.php?r=&count=VALUESENTHERE
That's probably the problem. You only want to include the variables in the URI if you're making a GET request. Remove them and it should work.

To conclude: Everything works, but why this is happening, I don't have any clue. It might be that we use ?r= and not anything else?
Doing just r= is a valid GET variable definition; it will just assign nothing to the variable (in PHP it will end up being an empty string).

I have litterally idea of what you are talking about. But what about this:

var xmlHttp = getXMLHttp();
        var async = false;
        var countForPHP = globalCounter;
        globalCounter = 0;
        xmlHttp.open("POST", "count.php", async);
        xhr.send('count=' + countForPHP);
NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Reducing the size of XHR? 2012-09-08 11:34:25 Reply

At 9/7/12 03:06 PM, Diki wrote: So Nino was right with his original conclusion that escaping or prepared statements are not really necessary in this esoteric situation.

Do I get cake?

Uglybetty, use jQuery, it's so much easier.
Example: http://portfolio.recgr.com/add.php
Lines 58 - 81

I'm also giving response, which I guess you don't need to do, making it easier for you. What I am giving you is an example of jQuery powered AJAX request with POST.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Reducing the size of XHR? 2012-09-08 12:11:31 Reply

At 9/7/12 05:04 PM, uglybetty wrote: I have litterally idea of what you are talking about.

When you are performing a POST request you do not include the variables in your URI (they're encoded into the request itself), so you don't want to perform a request on, for example, http://mysite.com/foo/bar.php?id=42&name=butts, you will just want just http://mysite.com/foo/bar.php.

At 9/7/12 05:04 PM, uglybetty wrote: But what about this:

var xmlHttp = getXMLHttp();
var async = false;
var countForPHP = globalCounter;
globalCounter = 0;
xmlHttp.open("POST", "count.php", async);
xhr.send('count=' + countForPHP);

I'm not sure. What does getXMLHttp() return? An XMLHttpRequest object? Why are you sending with the xhr variable and not xmlHttp?
Other than that, yeah, that code looks like it should work.

At 9/8/12 11:34 AM, NinoGrounds wrote: Uglybetty, use jQuery, it's so much easier.
Example: http://portfolio.recgr.com/add.php
Lines 58 - 81

As much as I love jQuery I don't think he should be using it yet; he's still learning JavaScript, so it would behoove him to finish learning it before diving into a massive framework such as jQuery.

uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-09 08:27:52 Reply

At 9/8/12 12:11 PM, Diki wrote:
At 9/7/12 05:04 PM, uglybetty wrote: I have litterally idea of what you are talking about.
When you are performing a POST request you do not include the variables in your URI (they're encoded into the request itself), so you don't want to perform a request on, for example, http://mysite.com/foo/bar.php?id=42&name=butts, you will just want just http://mysite.com/foo/bar.php.

At 9/7/12 05:04 PM, uglybetty wrote: But what about this:

var xmlHttp = getXMLHttp();
var async = false;
var countForPHP = globalCounter;
globalCounter = 0;
xmlHttp.open("POST", "count.php", async);
xhr.send('count=' + countForPHP);
I'm not sure. What does getXMLHttp() return? An XMLHttpRequest object? Why are you sending with the xhr variable and not xmlHttp?
Other than that, yeah, that code looks like it should work.

I've been trying to get the code working but no luck. In Google Chrome I get a message saying a function is anonymous. Function submitCount is apparanlty anonymous.

I included all my code now (for more clearity.). As for the XHR? It's just a cross-browser handler if the user does not have a farly modern browser.

function getXMLHttp() {
    var xmlHttp;
    try {
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                return false;
            }
        }
    return xmlHttp;
}

function submitCount(){
    if (globalCounter > 0)
    {
        var xmlHttp = getXMLHttp();
        var countForPHP = globalCounter;
        globalCounter = 0;
        xmlHttp.open("POST", "count.php", false);
        xmlHttp.send("count="+ countForPHP);
    }
    window.setTimeout("submitCount();",5000);
}
At 9/8/12 11:34 AM, NinoGrounds wrote: Uglybetty, use jQuery, it's so much easier.
Example: http://portfolio.recgr.com/add.php
Lines 58 - 81
As much as I love jQuery I don't think he should be using it yet; he's still learning JavaScript, so it would behoove him to finish learning it before diving into a massive framework such as jQuery.

Personally, I do not like using librarys. But when I was programming a little from my uncle, I had to use Mootools. It's worth checking out if you haven't already. :)

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Reducing the size of XHR? 2012-09-09 10:07:05 Reply

At 9/9/12 08:27 AM, uglybetty wrote: I had to use Mootools. It's worth checking out if you haven't already. :)

I did, and jQuery owns it

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Reducing the size of XHR? 2012-09-09 10:34:57 Reply

At 9/9/12 08:27 AM, uglybetty wrote: Personally, I do not like using librarys

Why not? They can save you hours of work, and possibly perform better than anything you could write yourself.
Plus reinventing the wheel sucks. Don't fall victim to NIH syndrome.

At 9/9/12 10:07 AM, NinoGrounds wrote: I did, and jQuery owns it

How? Why?
Both are excellent frameworks; neither is better than the other.

uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-09 13:47:00 Reply

At 9/9/12 10:34 AM, Diki wrote:
At 9/9/12 08:27 AM, uglybetty wrote: Personally, I do not like using librarys
Why not? They can save you hours of work, and possibly perform better than anything you could write yourself.
Plus reinventing the wheel sucks. Don't fall victim to NIH syndrome.

I am not quite sure, but I was raised to do things on my own. Anyways, everything works as it should - not sure what was wrong, but apparantly it does work properly now.

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Reducing the size of XHR? 2012-09-09 16:13:26 Reply

At 9/9/12 10:34 AM, Diki wrote: How? Why?
Both are excellent frameworks; neither is better than the other.

No idea, but since jQuery is so much more popular, I thought it figures it is better too.

uglybetty
uglybetty
  • Member since: Apr. 4, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Reducing the size of XHR? 2012-09-09 16:51:11 Reply

At 9/9/12 04:13 PM, NinoGrounds wrote:
At 9/9/12 10:34 AM, Diki wrote: How? Why?
Both are excellent frameworks; neither is better than the other.
No idea, but since jQuery is so much more popular, I thought it figures it is better too.

Leif K-Brooks uses MooTools :)

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Reducing the size of XHR? 2012-09-10 04:43:21 Reply

At 9/9/12 04:51 PM, uglybetty wrote: Leif K-Brooks uses MooTools :)

APE too, but I'd still stick with jQuery.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Online!
Forum Stats
Supporter
Level 05
Game Developer
Response to Reducing the size of XHR? 2012-09-10 08:11:59 Reply

At 9/6/12 01:50 PM, Diki wrote: It's poorly named, but whattya gonna do?
function intern_san($string){
	global $options, $master_link, $master_connect, $slave_link, $slave_connect;
	
	$string = mysql_real_escape_string($string);
	
	return $string;
}

it's terrible, but I have two reasons for doing it.

1. I haven't finished my scripts yet, and i'll be adding to that function later (reason for the globals)
2. The last thing I need is carpal tunnel

but yeah. That's one way to avoid having to type that long-ass function name every time you want to run a query.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Reducing the size of XHR? 2012-09-10 10:45:10 Reply

At 9/9/12 04:13 PM, NinoGrounds wrote: No idea, but since jQuery is so much more popular, I thought it figures it is better too.
At 9/10/12 04:43 AM, NinoGrounds wrote:
At 9/9/12 04:51 PM, uglybetty wrote: Leif K-Brooks uses MooTools :)
APE too, but I'd still stick with jQuery.

You should actually check out MooTools, it has some handy features that aren't found in jQuery, such as the lambda, extend, and try functions.

Both frameworks do a lot of the same things in slightly different ways (such as event handling) but in the end they are vastly different frameworks. jQuery is pretty much only useful if you're manipulating the DOM. MooTools is useful for manipulating the DOM, but it really shines you're writing JavaScript that doesn't involve the DOM.

In short: MooTools does for JavaScript what jQuery does for the DOM, and, as such, they are not comparable and neither is better than the other.