Frage

Ich bin neu in Ajax. Ich mag ein verstecktes Feld mit einem response vom Server auf einem Formular füllen. Ich bin in der Lage, die response im HTML als innerHTML- angezeigt werden soll. Ich bin nur nicht sicher, wie auf dem Formular das versteckte Feld zu füllen. Alle Vorschläge werden sehr geschätzt!

:)

Hier ist die JS:

  function getLocation(locationrouting) 
    {
   var getLocation= newXMLHttpRequest(); // sending request
   getLocation.open("GET", "/PP?PAGE=GETLOCATIONNAME&ROUTINGNUM=" + locationrouting, false);
   getLocation.send(null); // getting location

     var dv = document.getElementById("location_div");
     var verifyUnfound()

     if (getlocation.responseText === 'LOCATION NOT FOUND')
     {
       dv.style.color = "red";
     }
      else 
     {
      dv.style.color = "black";
    }
   dv.innerHTML = getLocation.responseText;
    }
War es hilfreich?

Lösung

HTML:

<input type="hidden" id="someid" name="somename" value="somevalue">

JS:

var hiddenField = document.getElementById('someid');
hiddenField.value = <whatever>;

Sie können Ihre Funktion ändern:

function getLocation(locationrouting) {
    var getLocation= newXMLHttpRequest(); // sending request
    getLocation.open("GET", "/PP?PAGE=GETLOCATIONNAME&ROUTINGNUM=" + locationrouting, false);
    getLocation.send(null); // getting location

    var dv = document.getElementById("location_div");
    var verifyUnfound();
    var hiddenField = document.getElementById('someid');

    if (getlocation . responseText === 'LOCATION NOT FOUND') {
        dv.style.color = "red";
    } else {
        dv.style.color = "black";
    }
    dv.innerHTML = getLocation . responseText;
    hiddenField.value = getLocation . responseText;
}

Andere Tipps

Mit jQuery, es wird den Wert und macht die AJAX-Request erleichtern Einstellung.

$("#something").attr("value", myvalue)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top