Should I add AJAX logic to my PHP classes / scripts?

I was just starting to create a PHP / AJAX site, and I was wondering where I should add functionality, "including only content .

Should I have if statements in my header and footer scripts that check the "ContentOnly" get parameter ? And then add this parameter to the query strings in my AJAX calls?

Or should I use an AJAX-side filter to grab the main content of the Div. Like in jquery:

$(this).load("/myPhpPage.php #mainContentDiv")

Will the first method be faster? But the second method will retain AJAX functionality on the presentation side and outside of my PHP.

Or is there a third method? I want my PHP scripts to be intact, so if oyu goes directly to them, then there is a header and footer. Thanks in advance!

+2
source share
5 answers

Please do not use AJAX to use AJAX.

However, most AJAX libraries send an HTTP header X-Requested-Withindicating that this is an AJAX request. You can use this header to decide whether to include its header / footer, etc.

+7
source

, , ​​ script. , , .

ceejayoz, X-Requested-With (, javascript- ajax!), script, , .

+1

, . javascript - javascript , .

, , . , , - JSON, , , . , , . , , .

, AJAX, .

+1

X-Requested-With :

, ... AJAX, - - XML , . , , , . X-Requested-With, .

0

X-Requested-With HTTP, , Ajax . Ajax- HTML, !

AJAX html . , mime mime. , HTML, HTML, AJAX- XML JSON, , .

: AHAH - ( ). OP, mime-type.

, ajax - , , . AJAX , .

AHAH , ( ), , :)

, (, treeview), , javascript-abled -disabled, , javascript-abled.

btw, , , , , , .

-2

Source: https://habr.com/ru/post/1703377/


All Articles