|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I am revisiting something that we started some time ago. We are about to start sharing some of our content, and this content will change automatically. For example, a list of events, which will update itself.
This will be included on other peoples sites. Those webmasters will need to "add a line of code", specifying what they want to see on their site. I thought that the first place to look for an example would be Google Ads, where they put stuff onto other peoples sites. But Google ads are called with Javascript. Obviously, the code must interrogate a database somewhere along the line, so the Javascript must call something else, as Javascript can't reach a database. So why call the ads with Javascript, when you could call a PHP file? Seems like this would slow things down slightly, having to call a PHP / ASP file to get the data from a database. Why not call the PHP / ASP file direct? I have a test working, calling a PHP file, with parameters, which will then format the results and add it to other peoples sites. But I can't help thinking that I could have missed something, if Google did it a different way! Anyone know why Javascript was used to fetch Google Ads? |
|
||||
|
The javascript in google ads uses inlined JSON to display content fetched from Google's servers. JSON is a lightweight computer data interchange format. It is a text-based, human-readable format for representing simple data structures and associative arrays (called objects).
JSON - Wikipedia, the free encyclopedia Not all websites are php enabled, not all servers even host php, any website can insert javascript in html though and be sure for expected result, not every website can insert a line of php to the html code. If you are sharing some changing content fom your website, have you thought of simply using rss, as that is widely used, easy to implement for anyone who wanted to place your shared content, so would be widely distributable...Google ads require some tracking and stuff, if you are sharing content that maybe all you need... |
|
|||
|
But surely JSON can't just be run from Javascript without an intermediary script? Can it?
I have tested the "include" line in HTML only files, that are not parsed for PHP, and it works fine. The code is called from my server, which can parse PHP, and so includes the expected output, even in HTML files. I don't think that RSS is as simple as you imply, I want complete beginners to be able to insert a line of code, and pic up the information. RSS doesn't do that, it requires some kind of RSS reader on the receiving site, and that isn't always available. And I do want the feedback anyway. I have used JSON, I will look at it again, but I need to pass some HTML to the receiving sites, so that there will be a default layout for those sites. The JSON that I have used in the past (on my own sites) was called from PHP (json_decode, etc) But I will look at JSON again.
__________________
Pete Clark Got any spare time? Anything you need? Barter in Spain at http://BarterWithBart.com |
|
|||
|
I'm not a technical person but I feel that by using Javascript one can use limited bandwidth space.
__________________
Download Free DVD Movies || Cold Sore Treatment || Best eBooks & Software Downloads || |
|
|||
|
Quote:
Have a look at Untitled This also works as file://C:\develop... \temp.html (whatever the correct syntax is!) from my local drive, by just clicking on it, no apache, nothing, just Windows Vista. The "line to add" is <script type="text/javascript" src="http://www.hotcosta.com/js/ip.php?a=ab&b=cd"></script> The php is on the "called" server, in this case, hotcosta.com The only issue with this is, if I run it from my Windows PC local drive, I get an ActiveX warning with IE. But this does not appear when I call it from buydirectfromowners.com. And I can't figure out why this happens. Perhaps there is something in the ActiveX warning that stopped Google from doing this with the ads? But it doesn't appear when I am calling the html file from a website. If I could find a server with no PHP, perhaps I could try it. But I don't know any. |
|
|||
|
Quote:
But Javascript can't read the database on the server, to pull out the info. It would have to call another file, in my case, a PHP file, and the PHP file would pull out the info, pass it to the browser, and the Javascript would then have to place the data into the page. This is the sort of thing that Ajax does, but Ajax is great for changes once the page is loaded (user clicks, and part of the page changes), and in THAT way, the bandwidth is reduced, because instead of re-loading the entire page, only the changed section is loaded (or reloaded). Using this system during a page download just seems to waste time, if the PHP file can be called directly. |
|
||||
|
Quote:
Please make up your mind about what you are doing before asking a question about it. |
|
|||
|
Please make up your mind if you have anything useful to add before adding it
__________________
Pete Clark Got any spare time? Anything you need? Barter in Spain at http://BarterWithBart.com |
|
||||
|
Quote:
Code:
<script type="text/javascript">
document.write("<h1>Hello World!</h1>");
</script>
The .htaccessline differs somewhat across servers, on mine the line is Code:
AddType application/x-httpd-php .htm .html Code:
AddType application/x-httpd-php .htm .html .js With php being parsed within a javascript on your server, you can then put dynamic php data in the javascript that is hosted on your server such as Code:
document.write("<h1><?php echo $var ?></h1>");
JavaScript Syndication: How to Easily Syndicate Your Web Content Last edited by chandrika; 12-26-2009 at 06:09 PM. |
|
|||
|
Wow! A full example explaining how to parse PHP inside a Javascript file! I didn't know that you could do that!
And the page that you sent me to, appears to have a complete example to work from. Excellent. Doing it this way, means that the IE ActiveX warning never appears under any circumstances. Thanks for the input, it's appreciated. |
|
||||
|
Quote:
You also started by querying "why call the ads with Javascript, when you could call a PHP file?" and then later, when explaining a solution, reveal that you've seen it done with JavaScript: The "line to add" is <script type="text/javascript" src="http://www.hotcosta.com/js/ip.php?a=ab&b=cd"></script> The php is on the "called" server, in this case, hotcosta.com What I was adding, usefully, to the conversation is that we'll all find it rather difficult to score (answer your query) when you keep moving the goalposts (changing your question). |
|
|||
|
The question never changed. "Why are Google Ads called in Javascript" was the original question.
I was saying that, as Javascript can't access a database, it appears that Javascript has to call something else, wasting more time at a critical point. Google's Ad code calls Javascript, my code was calling PHP, eliminating one step on the ad server. I couldn't understand why Google were calling a .js file. chandrika helpfully pointed out that Javascript could be parsed for PHP, their implication being that you can call .js, and parse it for PHP, thus avoiding the need for calling a second file on the server. The question is answered. "because Javascript can be parsed for PHP"
__________________
Pete Clark Got any spare time? Anything you need? Barter in Spain at http://BarterWithBart.com |
|
|||
|
i have just written an in depth guide on how you can do what you want and why google do it that way. and how you can use the same tricks as they do but this stupid site does not let me post it !
Well done |
|
|||
|
btw way simple answer: server side included do not (in basic format) send client info back to google. Javascript includes (as that is essentially what they are) can and do send everything about the users browser and computer back to the src file (php asp pl) that dumps that info into googles fat server farm. And decent browser supports a single line of javascript. a server side script would have to be available in many, php, perl, asp(vbscript) aspx(C#. vb.net, Jscript), ruby, python the list goes on and on..
That my friend is THE ANSWER |
|
|||
|
You could use PHP even if the site that is hosting your content doesn't have PHP i.e. just have them call it remotely by an image file. For a good example see Free Trust Seal d com
|
|
||||
|
If you really have something of value to share, you can type domainDOTcom/file ...
__________________
M.-J. Taylor SEO Web Design by Cyber Key Search Smart DesignŽ SEO Copywriter & Traveling Vacation Gypsy |
|
||||
|
1. JavaScript dynamic content can be added to any type of site, including static html sites.
Inclusion is same for php, asp, jsp, plain html sites. 2. Client server side code would have to query the google servers to get data (ads to show). That means some delay before receiving response and displaying the final content. JavaScript loads after page rendering without causing delays. 3. Client server side code would not allow controlling what type of ads show on different pages depending on context. People could get some ads and display these on irrelevant pages, newsletters. Also counting impression would not be possible. Ads could be fetched once and displayed multiple times.
__________________
VideoWhisper Flash Video Streaming features for websites: Video Conference, Video Recorder, 2 Way Video Chat, Live Streaming, Video Consultation. Free versions to download. |
|
||||
|
Quote:
Code is executed either on the server or the client, but not both. JScript is client-side. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help! I think I'm under attack by a bot called startdedicated | wilderness | Internet Security Discussion Forum | 16 | 10-03-2008 08:04 PM |
| A network called 'Internet' | whipnet | The Castle Breakroom (General: Any Topic) | 1 | 07-15-2006 03:18 PM |
| They have to be called something | coder | The Castle Breakroom (General: Any Topic) | 12 | 06-28-2005 04:48 PM |
| CRM program called Maximizer | tntpics | Database Discussion Forum | 0 | 11-18-2004 12:56 PM |
| What's the called? | wbsweb | Web Programming Discussion Forum | 3 | 01-28-2004 11:55 AM |
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2010 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |