Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Very simple php script not working in IE

Featured Replies

Hey,

 

Basically I have a .txt file with a sentence on each line, and every time I press the a button it chooses a new one...

 

The Button:

<input type="button" value="Change Article" id="articleswap" onclick='$("#articalinfo").load("newarticle.php")'>

 

The php (in a newarticle.php file):

 

<?php 
   $arr = explode( "\n", file_get_contents( "artic.txt" ) );
   echo $arr[ rand( 0, count( $arr ) - 1 ) ];
?> 

 

Works fine in FF, every time the button is clicked it randomly chooses a new line and displays it. However in IE I can only click it, a line is displayed and then it wont work again :s

 

Anyone know why?

 

Also:

Does anyone know how I could display the lines one after the other instead of randomly?

Try

 

<input type="button" value="Change Article" id="articleswap" onclick="$('#articalinfo').load('newarticle.php', function() { return true; }); return true;" />

  • Author

Nope does exactly the same :(

  • Author

Do you mean:

 

onclick="$('#articalinfo').load('
http://www.elliothesp.co.uk/assignment/newsarticle.php', function() { return true; }); return true;"

 

Do you mean that? If so it doesnt load it at all

That should work (as long as its on the same domain). Can you post the full HTML code?

  • Author

Ah well i put the jQuery in an new file :p Dont want any more kittens to perish now D:

 

Basically all it is:

 

index.php;

 

the button

<div id="articalbutton"><input type="button" value="Change Article" id="articleswap"/>
</div>

 

the space:

<div id="articalinfo">
<!-- DUMMY ARTICLE -->
HTML:<br />
HTML, which stands for HyperText Markup Language, is the predominant markup language for web pages. A markup language is a set of markup tags, and HTML uses markup tags to describe web pages. HTML is written in the form of HTML elements consisting of "tags" surrounded by angle brackets (like ) within the web page content. HTML tags normally come in pairs like and . The first tag in a pair is the start tag, the second tag is the end tag (they are also called opening tags and closing tags). The purpose of a web browser is to read HTML documents and display them as web pages. The browser does not display the HTML tags, but uses the tags to interpret the content of the page. HTML elements form the building blocks of all websites. HTML allows images and objects to be embedded and can be used to create interactive forms. It provides a means to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists, links, quotes and other items. 

</div>

^^ This is so that when the page loads there is already something there, and when the button is clicked it changes it.

 

.js file:

		$('#articleswap').click(function() {
 			$("#articalinfo").load("http://localhost/assignment/newarticle.php");
});

Running it through xampp thus the local host atm.

 

Then in a seperate newarticle.php file:

 

<?php 
   $arr = explode( "\n", file_get_contents( "artic.txt" ) );
   echo $arr[ rand( 0, count( $arr ) - 1 ) ];
?> 

  • Author

Anyone? Im stumpped :|

Is IE caching the response? Try this code...

 

$('#articleswap').click(function(e) {
   $("#articalinfo").load("http://localhost/assignment/newarticle.php?t=" + Math.random()*99999);
   e.preventDefault();
});

 

If that doesn't work, you could try ditching the load function and use getJson() or post() or get() to get the random article and use html() to update the div.

  • Author

Ahh thank you sir!

Never even thought about that :)

 

Stupid IE, wonder why it has to do that :s Thanks so much anyway!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.