Bär mit mir Ich bin mein Javascript ist ein wenig eingerostet. Ich versuche also, einen Aufruf von Ajax zu einer PHP - Datei zu verwenden und ihm einen Plan - Typ zu geben, der dann Sinn macht, um zu sehen, ob er dann einen Wahr - oder Falsch - Wert zurückgibt, wenn einige erlaubte Plätze weniger als einige belegte Plätze sind planen. Hier ist das Formular in XHTML.Ajax funktioniert nicht richtig
<form method="post" action="/membership-change-success" id="PaymentForm">
<input type="hidden" name="planChosen" id="planChosen" value="" />
</form>
In derselben Datei. Die (< PLANAUSWAHL>) wird in den aktuellen Plan zerlegt.
<script>
var hash = window.location.hash;
var currentPlan = "(< PLAN CHOICE >)";
$(".planChoice").click(function(event){
var isGood=confirm('Are you sure you want to change your plan?');
var success;
$("#planChosen").val($(this).data("plan"));
$.ajax({
url: '/ajax/planCheck.php',
type: "POST",
dataType: 'json',
data: ({plan: $(this).data("plan")}),
success: function (data) { //This is what is not working I can't get it to return true
success = data;
}
});
if(success) {
if (isGood) {
$("#PaymentForm").submit();
}
window.location = '/membership-change-success';
} else {
alert('Please make sure you deactivate your listings to the appropriate amount before you Downgrade.')
}
});
Mein PHP für die Ajax-Antwort sieht so aus.
<?php
require ('../includes/common.php');
include_once ('../includes/db-common.php');
require ('../includes/config.php');
$membership = new membership($dbobject);
$listing = new listing($dbobject);
$totalAvailableListings = ($membership->get_listingsAmount($_POST['plan']));
if($totalAvailableListings>=$listing->get_active_listings($user->id)){
echo json_encode(true); // I've tried with out jason_encode too
} else {
echo json_encode(false);
}
Und das ist so ziemlich es, wenn Sie irgendwelche Vorschläge haben, lass es mich wissen.
Also habe ich versucht, es auf eine andere Weise zu tun.
$(".planChoice").click(function (event) {
var isGood = confirm('Are you sure you want to change your plan?');
var success;
$("#planChosen").val($(this).data("plan"));
if (false) {
if (isGood) {
$("#PaymentForm").submit();
alert('you did it');
}
} else {
alert(isSuccessful($(this).data("plan")));
//alert('Please make sure you deactivate your listings to the appropriate amount before you downgrade.');
}
});
und ich habe eine Ajax-Funktion
function isSuccessful(plan) {
return $.ajax({
url: '/ajax/planCheck.php',
type: "POST",
dataType: 'json',
data: {plan: plan}
});
}
Die Warnung sagt mir dieses [Objekt XMLHttpRequest]
irgendwelche Vorschläge?
Also, was ist dein Problem? – epascarello
'Erfolg: Erfolg = Daten' ist falsch Sie sollten einen Rückruf haben, der – epascarello
https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – epascarello