Gå til innhold

klarer ikke printe ut et javascript med echo funksjonen!


Anbefalte innlegg

Har irritert meg over dette i 2 dager nå. Har et langt javascript som jeg skal printe ut med php ved å bruke echo. Noe jeg har gjort hundre ganger før, men nå funker det ikke av en eller annen grunn.. Vet at det er en eller annen pitteliten feil jeg har oversett som gjør at det hele ikke fungerer, men finner den ikke. Jeg er 100% sikker på at det ligger en feil her, men finner den ikke... Ekstremt irriterende..

 

Her er echo'ingen, please se over koden å finn feilen. Hadde gjort meg en kjempe tjeneste

 

	public function displayNotifyJs()
{
	echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"css/ui.notify.css\" />";
	echo "<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js\" type=\"text/javascript\"></script>\n";
	echo "<script src=\"http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js\" type=\"text/javascript\"></script>\n";
	echo "<script src=\"js/jquery.notify.js\" type=\"text/javascript\"></script>\n";
	echo "<script type=\"text/javascript\">\n";
	echo "  $.noConflict();\n";
	echo "  jQuery(document).ready(function($) {\n\n";

	echo "function create( template, vars, opts ){\n";
	echo "return \$container.notify(\"create\", template, vars, opts);\n";
	echo "}\n\n";

	echo "$(function(){\n";
	// initialize widget on a container, passing in all the defaults.
	// the defaults will apply to any notification created within this
	// container, but can be overwritten on notification-by-notification
	// basis.
	echo "\$container = $(\"#container\").notify();\n";

	// create two when the pg loads
	echo "create(\"default\", { title:'Default Notification', text:'Example of a default notification. I will fade out after 5 seconds'});\n";
	echo "create(\"sticky\", { title:'Sticky Notification', text:'Example of a \"sticky\" notification. Click on the X above to close me.'},{ expires:false });\n\n";

	// bindings for the examples
	echo "$(\"#default\").click(function(){\n";
	echo "create(\"default\", { title:'Default Notification', text:'Example of a default notification. I will fade out after 5 seconds'});\n";
	echo "});\n";

	echo "$(\"#sticky\").click(function(){\n";
	echo "create(\"sticky\", { title:'Sticky Notification', text:'Example of a \"sticky\" notification. Click on the X above to close me.'},{ expires:false });\n";
	echo "});\n";

	echo "$(\"#warning\").click(function(){\n";
	echo "create(\"withIcon\", { title:'Warning!', text:'OMG the quick brown fox jumped over the lazy dog. You\'ve been warned. <a href=\"#\" class=\"ui-notify-close\">Close me.</a>', icon:'images/alert.png' },{\n";
	echo "expires:false\n\n";
	echo "});\n";
	echo "});\n";

	echo "$(\"#themeroller\").click(function(){\n";
	echo "create(\"themeroller\", { title:'Warning!', text:'The <code>custom</code> option is set to false for this notification, which prevents the widget from imposing it\'s own coloring. With this option off, you\'re free to style however you want without changing the original widget\'s CSS.' },{\n";
	echo "custom: true,\n";
	echo "expires: false\n";
	echo "});\n";
	echo "});\n\n";

	echo "$(\"#clickable\").click(function(){\n";
	echo "create(\"default\", { title:'Clickable Notification', text:'Click on me to fire a callback. Do it quick though because I will fade out after 5 seconds.'}, {\n";
	echo "click: function(e,instance){\n";
	echo "alert(\"Click triggered!\n\nTwo options are passed into the click callback: the original event obj and the instance object.\");\n";
	echo "}\n";
	echo "});\n";
	echo "});\n\n";

	echo "$(\"#buttons\").click(function(){\n";
	echo "var n = create(\"buttons\", { title:'Confirm some action', text:'This template has a button.' },{\n";
	echo "expires:false\n\n";
	echo "});\n\n";

	echo "n.widget().delegate(\"input\",\"click\", function(){\n";
	echo "n.close();\n";
	echo "});\n";
	echo "});\n\n";


	echo "container.notify(\"widget\").find(\"input\").bind(\"click\", function(){\n";
	echo "container.notify(\"create\", 1, { title:'Another Notification!', text:'The quick brown fox jumped over the lazy dog.' });\n";
	echo "});\n";
	echo "});\n\n";


	echo "  });\n";
	echo "</script>\n";

}	

Lenke til kommentar
Videoannonse
Annonse

jeg er ingen php-wizard, og det er en stund siden sist jeg programmerte php, menså vidt jeg kan se bryter mange av gåseøynene med hverandre.

 

 

tar man første linjen:

 

echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"css/ui.notify.css\" />";

 

så vil jo den echoe "<link type=\" for så å bryte...

 

Det vil nok heller være bedre å bruke echo '<link type=\"text/css\" rel=\"stylesheet\" href=\"css/ui.notify.css\" />';

 

edit: forøvrig er det en tungvindt måte å implementere ett javascript, det burde være en eller annen måte å echoe hele tekstblokken med en echo, enn å echoe hver eneste linje. Tenker da at det må gå an å sette echo på starten av første linjen og avslutte med ; på siste linjen

Endret av Ducktoy
Lenke til kommentar

jeg er ingen php-wizard, og det er en stund siden sist jeg programmerte php, menså vidt jeg kan se bryter mange av gåseøynene med hverandre.

 

 

tar man første linjen:

 

echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"css/ui.notify.css\" />";

 

så vil jo den echoe "

Helt feil. Grunnen til at trådstarter (og alle andre) setter \ foran, er for å "escape" tegnet som kommer bak. Man kan dermed bruke gåseøyne i slike situasjoner.

 

Noe jeg derimot ikke skjønner, er hvorfor han velger å ha en echo-kommando for hver linje. Du vet du kan gjøre dette?

 

echo "lorem
ipsum
dolor
sit
amet";

 

Les mer om echo() i PHP-manualen.

Lenke til kommentar

Fungerte greit for meg, siden blir selvfølgelig tom, men ikke kildekoden ;)

 

 

 

<link type="text/css" rel="stylesheet" href="css/ui.notify.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js" type="text/javascript"></script>
<script src="js/jquery.notify.js" type="text/javascript"></script>
<script type="text/javascript">
 $.noConflict();
 jQuery(document).ready(function($) {

function create( template, vars, opts ){
return $container.notify("create", template, vars, opts);
}

$(function(){
$container = $("#container").notify();
create("default", { title:'Default Notification', text:'Example of a default notification. I will fade out after 5 seconds'});
create("sticky", { title:'Sticky Notification', text:'Example of a "sticky" notification. Click on the X above to close me.'},{ expires:false });

$("#default").click(function(){
create("default", { title:'Default Notification', text:'Example of a default notification. I will fade out after 5 seconds'});
});
$("#sticky").click(function(){
create("sticky", { title:'Sticky Notification', text:'Example of a "sticky" notification. Click on the X above to close me.'},{ expires:false });
});
$("#warning").click(function(){
create("withIcon", { title:'Warning!', text:'OMG the quick brown fox jumped over the lazy dog. You\'ve been warned. <a href="#" class="ui-notify-close">Close me.</a>', icon:'images/alert.png' },{
expires:false

});
});
$("#themeroller").click(function(){
create("themeroller", { title:'Warning!', text:'The <code>custom</code> option is set to false for this notification, which prevents the widget from imposing it\'s own coloring. With this option off, you\'re free to style however you want without changing the original widget\'s CSS.' },{
custom: true,
expires: false
});
});

$("#clickable").click(function(){
create("default", { title:'Clickable Notification', text:'Click on me to fire a callback. Do it quick though because I will fade out after 5 seconds.'}, {
click: function(e,instance){
alert("Click triggered!

Two options are passed into the click callback: the original event obj and the instance object.");
}
});
});

$("#buttons").click(function(){
var n = create("buttons", { title:'Confirm some action', text:'This template has a button.' },{
expires:false

});

n.widget().delegate("input","click", function(){
n.close();
});
});

container.notify("widget").find("input").
bind("click", function(){
container.notify("create", 1, { title:'Another Notification!', text:'The quick brown fox jumped over the lazy dog.' });
});
});

 });
</script>

 

 

Lenke til kommentar
  • 2 uker senere...

Siden du er inne på så "store" js script så vill jeg heller lagt det i en egen js fil og inkludert denne med script tagen.

Echoe ut noen få linjer istedenfor 100

 

EDIT:

Koden din vil se bedre ut (både js og php), og js koden vil bli mye lettere å redigere og feilsøke

Endret av AlecTBM
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...