Hallo Leute,
ich habe mal eine Frage. Und zwar bin ich seit ein paar Wochen dabei die gängigen Webprogrammiersprachen nach dem learning by doing Prinzip zu erlernen. Ich gehe dabei immer so vor, dass ich die einzelnen Skripte immer direkt auf dem xammp localhost erstmal teste und sie dann versuche in Wordpress einzubinden hierfür nutze ich das Plugin "PHP Code for Posts" mit dem ich eigentlich auch immer sehr zufrieden war. Jetzt kam es allerdings zu einem Problem. Ich will nach dem Ausfüllen eines Formulars direkt mittels AJAX eine DB Abfrage starten um dann darauf einen Wert auszugeben. Dies klappt allerdings nicht in Wordpress und es wird mir kein Wert angezeigt. Laut Firefox wird jedoch schon eine Post-Abfrage ausgeführt.
Hier mal die schematischen Codes:
<script src="http://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
function send_var(){
var selectone = document.getElementById("var1").value;
var selecttwo = document.getElementById("var2").value;
if (selectone > '0' && selecttwo > '0' )
{
$.ajax({
url: "http://localhost/wordpress/test-ii/",
data: {selectone: selectone, selecttwo: selecttwo},
datatype: "json",
type: "POST",
/* Callback-Funktion aufrufen */
success: function(data) {print_response(data);}
});
}
function print_response(data){
var antwort = $.parseJSON(data);
var response = antwort[1];
$("#ausgabe").html(response);
}
}
// -->
</script>
</head>
<body>
<form name="formula" action="">
<select name="var1" id="var1" onchange="send_var(this)">
<option value="0">Auswahl</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select name="var2" id="var2" onchange="send_var(this)">
<option value="0">Auswahl</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<p id="ausgabe"></p>
</form>
</body>
</html>
Alles anzeigen
[COLOR=#000000] [COLOR=#0000BB]<?php
$resultone [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_POST [/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'selectone'[/COLOR][COLOR=#007700]];
[/COLOR][COLOR=#0000BB]$resulttwo [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_POST [/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'selecttwo'[/COLOR][COLOR=#007700]];
[/COLOR][COLOR=#0000BB]$ergebniss [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$resultone [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000BB]$resulttwo[/COLOR][COLOR=#007700];
[/COLOR][COLOR=#0000BB]$ergebnisszwei [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"12512"[/COLOR][COLOR=#007700];
[/COLOR][COLOR=#0000BB]$array[/COLOR][COLOR=#007700]=array([/COLOR][COLOR=#0000BB]$ergebniss[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$ergebnisszwei[/COLOR][COLOR=#007700]);
echo [/COLOR][COLOR=#0000BB]json_encode[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$array[/COLOR][COLOR=#007700]);
[/COLOR][COLOR=#0000BB]?>[/COLOR] [/COLOR]
Alles anzeigen
Wäre euch um Hilfe wirklich sehr dankbar, da ich keine Ahnung habe, wie ich dieses Problem innerhalb Wordpress anzugehen habe.
VG Flo