48

Is there a difference in passing parameters to .load

$("#myDiv").load("myScript.php?var=x&var2=y&var3=z")

vs

$("#myDiv").load("myScript.php", {var1:x, var2:y, var3:z})

Also, is there a size limit to how much .load can handle? Can myScript.php return a couple hundred rows of data without issue?

kdauria
  • 6,300
  • 4
  • 34
  • 53

2 Answers2

43

In the first case, the data are passed to the script via GET, in the second via POST.

http://docs.jquery.com/Ajax/load#urldatacallback

I don't think there are limits to the data size, but the completition of the remote call will of course take longer with great amount of data.

Davide Gualano
  • 12,813
  • 9
  • 44
  • 65
29

As Davide Gualano has been told. This one

$("#myDiv").load("myScript.php?var=x&var2=y&var3=z")

use GET method for sending the request, and this one

$("#myDiv").load("myScript.php", {var:x, var2:y, var3:z})

use POST method for sending the request. But any limitation that is applied to each method (post/get) is applied to the alternative usages that has been mentioned in the question.

For example: url length limits the amount of sending data in GET method.

Ed DeGagne
  • 3,250
  • 1
  • 30
  • 46
Farshid Saberi
  • 917
  • 13
  • 15
  • I didn't find out why my answer has been marked by minus one. This is the exact deference in the current implementation of jQuery. Although my description was a little complicated and I tried to make it clear. – Farshid Saberi Jul 21 '14 at 11:02
  • I presume the initial downvotes were because your late answer very much mirrored the advice given by Davide many years earlier. – mickmackusa Apr 21 '22 at 02:33