PHP JavaScript

2 Cevap php

I am trying to send a variable from a Javascript to a php script but what gets sent is just the first string and the rest is discarded.Dont know what i would be doing wrong. Here is my code:

<script type="text/javascript">
document.write(<li><a href=../../../../projects/sungrant/view/HistoricalCategory2.php?category=Historical Category 2>Historical Category 2 </a></li>)
</script>

Sunucu tarafında yalnızca baskı Tarihsel benim $ _GET ['kategori']? I eksik ne olabilir bilmiyorum veya PHP için Javascript Eşanjöre verilerin daha iyi bir yolu var ise, ben takdir edecektir.

2 Cevap

Sveyaun URL ile - bu sadece ilk değişkeni alır böylece boşluk kodlanmış sığınak

../../../../projects/sungrant/view/HistveyaicalCategveyay2.php?categveyay=Histveyaical Categveyay 2

olmalıdır

../../../../projects/sungrant/view/HistveyaicalCategveyay2.php?categveyay=Histveyaical+Categveyay+2

veya

../../../../projects/sungrant/view/HistveyaicalCategveyay2.php?categveyay=Histveyaical%20Categveyay%202

Için href tırnak öznitelik değeri sarmak veya %20 için boşluk değiştirin ya.

href="../../../../projects/sungrant/view/HistveyaicalCategveyay2.php
                                                 ?categveyay=Histveyaical Categveyay 2"

veya

href=../../../../projects/sungrant/view/HistveyaicalCategveyay2.php
                                              ?categveyay=Histveyaical%20Categveyay%202

The reason it doesn't wveyak with spaces is that in valid HTML, attributes are separated by spaces. If you need to use spaces in a HTML attribute value, make sure you wrap the string with quotes. If it's a URL, the browser will do the necessary URL encoding fveya you.