2016-07-27 3 views
0

Vielleicht ist diese Frage schon beantwortet, aber ich verstehe es nicht. Ich benutze diesen Code.Javascript - Wie zwei Variablen in der URL übergeben?

function refresh() { 
      var $var=<?php echo "$var"; ?>  
      var posm = $("#posm").val(); 
      var url = window.location.href; 
      var index = url.indexOf('?'); 

      if (index > -1) { 
       url = url.substring(0, index); 
      } 
      url += "?posm=" + posm+"?var"+$var; 
      window.location.href = url; 
     } 

Ich möchte beide Variablen posm und $ var übergeben. posm wird übergeben, aber $ var wird nicht übergeben. Ich möchte Hilfe, um dieses Problem zu lösen.

+0

Die Syntax ist '? Foo = bar & baz = 42'. → '&' ← – deceze

+0

@deceze Ich habe es nicht verstanden. Willst du bitte ein wenig Ausarbeitung – Anonymous

+0

@ HK007: Vielleicht funktioniert das: 'url + ="? Posm = "+ posm +" & var "+ $ var;' – baris1892

Antwort

0

Verwendung dieser Code

function refresh() { 
     var $var='<?php echo $var; ?>';  
     var posm = $("#posm").val(); 
     var url = window.location.href; 
     var index = url.indexOf('?'); 

     if (index > -1) { 
      url = url.substring(0, index); 
     } 
     url += "?posm=" + posm+"&var="+$var; 
     window.location.href = url; 
    } 
+0

Vielen Dank es hat sehr geholfen. :) – Anonymous

Verwandte Themen