$status = $row->status;
switch ($status){
case "1":
$status = '<span class="badge badge-danger">Open</span> ';
break;
case "2":
$status= '<span class="badge badge-secondary">On Hold</span> ';
break;
case "3":
$status= '<span class="badge badge-success">In Progress</span> ';
break;
case "4":
$status= '<span class="badge badge-info">Closed</span> ';
break;
}
This is my switch statement in my php code ; How do i do the same insite ajax success : function(data)
This is my ajax function
success: function(response){
//console.log(response);
$('.sub').html(response.sub);
$('.msg').html(response.msg);
//value = $(this).val(response.status); //Get the value from db;
// if elseif or swithch statetment here//
$('.sts').html('<span class="badge badge-danger">Open</span>'); //post it to html div;
}
What can be done ?? is there any way to do it here or do i have to do it before encoding json?
You can also use switch case just like you use it in your php code like so:
success: function(response){
//console.log(response);
$('.sub').html(response.sub);
$('.msg').html(response.msg);
var status = response.status; //Get the value from db;
// if elseif or swithch statetment here//
switch (status) {
case "1":
$('.sts').html('<span class="badge badge-danger">Open</span>');
break;
case "2":
$('.sts').html('<span class="badge badge-secondary">On Hold</span>');
break;
case "3":
$('.sts').html('<span class="badge badge-success">In Progress</span>');
break;
case "4":
$('.sts').html('<span class="badge badge-info">Closed</span> ');
break;
default:
$('.sts').html('<span class="badge badge-danger">Open</span>');
}
}
Related
I don't know how I can do popup with result in my currency converter with API http://api.nbp.pl/. This is my code:
<?php
if (isset($_POST['kwota']) && isset($_POST['waluta']) && is_numeric($_POST['kwota']) && is_numeric($_POST['waluta'] )){
switch ($_POST['waluta']) {
case 1:
$przelicznik = json_decode(file_get_contents('http://api.nbp.pl/api/exchangerates/rates/a/usd/'))->rates[0]->mid;
break;
case 2:
$przelicznik = json_decode(file_get_contents('http://api.nbp.pl/api/exchangerates/rates/a/eur/'))->rates[0]->mid;
break;
case 3:
$przelicznik = json_decode(file_get_contents('http://api.nbp.pl/api/exchangerates/rates/a/jpy/'))->rates[0]->mid;
break;
case 4:
$przelicznik = json_decode(file_get_contents('http://api.nbp.pl/api/exchangerates/rates/a/gbp/'))->rates[0]->mid;
break;
case 5:
$przelicznik = json_decode(file_get_contents('http://api.nbp.pl/api/exchangerates/rates/a/aud/'))->rates[0]->mid;
break;
default:
$przelicznik = 1;
}
$wynik = $_POST['kwota']/$przelicznik;
echo $wynik;
}
?>
The API is public, so you tecnically don't need PHP to do so, you can fetch the exchange rate and show the results using javascript/jQuery directly.
Here's an example on how to do so using jQuery:
<form id="exchange">
<input type="text" name="price" title="price">
<select name="currency" title="currency">
<option value="1">USD</option>
<option value="2">EUR</option>
<option value="3">JPY</option>
<option value="4">GBP</option>
<option value="5">AUD</option>
</select>
<input type="submit" value="calculate">
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$('#exchange').on('submit',function(e){
e.preventDefault();
var value = $(this).find('[name="price"]').val();
if(!value) {
alert("Insert a valid value");
return false;
}
switch ($(this).find('[name="currency"]').val()) {
case "1":
$link = 'http://api.nbp.pl/api/exchangerates/rates/a/usd/';
break;
case "2":
$link = 'http://api.nbp.pl/api/exchangerates/rates/a/eur/';
break;
case "3":
$link = 'http://api.nbp.pl/api/exchangerates/rates/a/jpy/';
break;
case "4":
$link = 'http://api.nbp.pl/api/exchangerates/rates/a/gbp/';
break;
case "5":
$link = 'http://api.nbp.pl/api/exchangerates/rates/a/aud/';
break;
default:
alert('Error');
return false;
}
console.log($link);
$.getJSON($link,function(result){
alert(value/result.rates[0].mid);
});
});
</script>
In a Bootsrap page I'm using jQuery to send different formulars zu a .php. With the jQuery I'm trying to took the result from the .php to show it to the user. But when I got the result from the php, something happend that i cant understand:
The incoming response give's in the console following result:
command:
console.log("Test: "+response+"\n\n Test2: "+response.Richtwert1);
result:
Test: {"success": true, "Rechnung1": true, "Liter1": "2000",
"Entfernung1": "91.86", "Richtwert1": "2000", "PpLnetto1": "3.4",
"PpLbrutto1": "4.04", "Gesamtpreis1": "91.86", "Rechnung2": false,
"Rechnung3": false
Test2: undefined
Hope someone here can help me to get my values out of this response.
Following the important parts of my program:
part of jQ in index.html:
<script>
$(document).ready(function(){
$('#Rechnen_button').on('click',function(){
//Formular absenden
//Alte ErrorMeldungen entfernen
$( '#KundennameZeile' ).removeClass( 'has-error' );
$( '#LiterZeile1' ).removeClass( 'has-error' );
var formControl = true;
//Variable einsammeln
var Name = "Rechner";
var Kundenname = $( '#Kundenname' ).val();
var LiterAuswahlFeld1 = $( '#LiterAuswahlFeld1' ).text();
var Liter1 = $( '#Liter1' ).val();
var AB1 = $( '#AbladestellenAuswahlFeld1' ).text();
var Raten1 = $( '#RatenAuswahlFeld1' ).text();
var Ort = $( '#OrtAuswahlFeld' ).text();
var Oel1 = $( '#OelsorteAuswahlFeld1' ).text();
var LiterAuswahlFeld2 = $( '#LiterAuswahlFeld2' ).text();
var Liter2 = $( '#Liter2' ).val();
var AB2 = $( '#AbladestellenAuswahlFeld2' ).text();
var Raten2 = $( '#RatenAuswahlFeld2' ).text();
var Oel2 = $( '#OelsorteAuswahlFeld2' ).text();
var LiterAuswahlFeld3 = $( '#LiterAuswahlFeld3' ).text();
var Liter3 = $( '#Liter3' ).val();
var AB3 = $( '#AbladestellenAuswahlFeld3' ).text();
var Raten3 = $( '#RatenAuswahlFeld3' ).text();
var Oel3 = $( '#OelsorteAuswahlFeld3' ).text();
//Kontrolle ob alles wichtige für Rechnung 1 da ist
if(Kundenname == '') {
formControl = false;
$( '#KundennameZeile' ).addClass( 'has-error' );
}
if(Liter1 == '') {
formControl = false;
$( '#LiterZeile1' ).addClass( 'has-error' );
}
if($.isNumeric(Liter1) == false) {
formControl = false;
$( '#LiterZeile1' ).addClass( 'has-error' );
}
if(formControl) {
//Rechnung abschicken
$.ajax({
type: "POST",
url: "post.php",
data: {
name:Name,
Kundenname:Kundenname,
LiterAuswahlFeld1:LiterAuswahlFeld1,
Liter1:Liter1,
AB1:AB1,
Raten1:Raten1,
Ort:Ort,
Oel1:Oel1,
LiterAuswahlFeld2:LiterAuswahlFeld2,
Liter2:Liter2,
AB2:AB2,
Raten2:Raten2,
Oel2:Oel2,
LiterAuswahlFeld3:LiterAuswahlFeld3,
Liter3:Liter3,
AB3:AB3,
Raten3:Raten3,
Oel3:Oel3
},
success: function(response) {
console.log("Test: "+response+"\n\n Test2: "+response.Richtwert1);
if(!response.success) {
return response.msg;
} else {
$('#RichtwertErgebnis1').html(response.Richtwert1+' L.');
$('#EntfernungErgebnis1').html(response.Entfernung1+' €');
$('#PlLnettoErgebnis1').html(response.PpLnetto1+' Ct');
$('#PpLbruttoErgebnis1').html(response.PpLbrutto1+' Ct');
if(LiterAuswahlFeld1=="Liter") {
$('#GesamtbruttoErgebnis1').html(response.Gesamtpreis1+' €');
} else {
$('#GesamtbruttoErgebnis1').html(response.Gesamtpreis1+' € ergeben '+response.Liter1+' L.');
$('rechnungsergebnis_1 span:last-child').html('Gesamt brutto ergibt Liter');
}
}
}
});
}
})
})
</script>
The post.php:
<?php
include 'config.php';
$name = $_POST['name'];
if (strlen($name) > 0) {
if($name=='Rechner'){
//Rechnung durchführen
$Kundenname = $_POST['Kundenname'];
$LiterAuswahlFeld1 = $_POST['LiterAuswahlFeld1'];
$Liter1 = $_POST['Liter1'];
$AB1 = $_POST['AB1'];
$Raten1 = $_POST['Raten1'];
$Ort = $_POST['Ort'];
$Oel1 = $_POST['Oel1'];
$LiterAuswahlFeld2 = $_POST['LiterAuswahlFeld2'];
$Liter2 = $_POST['Liter2'];
$AB2 = $_POST['AB2'];
$Raten2 = $_POST['Raten2'];
$Oel2 = $_POST['Oel2'];
$LiterAuswahlFeld3 = $_POST['LiterAuswahlFeld3'];
$Liter3 = $_POST['Liter3'];
$AB3 = $_POST['AB3'];
$Raten3 = $_POST['Raten3'];
$Oel3 = $_POST['Oel3'];
//Something for you unimporant is deleted
if(strlen($name) > 0 && ((strlen($Liter1) > 0 && is_numeric($Liter1))||(strlen($Liter2) > 0 && is_numeric($Liter2))||(strlen($Liter3) > 0 && is_numeric($Liter3)))) {
if(strlen($Liter1) > 0 && is_numeric($Liter1)) {
//Rechnung 1
//Variablen Kontrolle
if($LiterAuswahlFeld1!=='Max. Betrag') {$LiterAuswahlFeld1="Liter";}
switch ($AB1) {
case 1;
case 2;
case 3;
case 4;
case 5;
case 6;
case 7;
case 8;
break;
default:
$AB1=1;
break;
}
switch ($Raten1) {
case 1:
$Raten1=0;
break;
case 2:
$Raten1=1;
break;
case 3;
$Raten1=2;
break;
default:
$Raten1=0;
break;
}
if($Oel1!=='Premium Heizöl') {$Oel1="Heizöl EL";}
//Werte berechnen
$rechnung1=preisrechner($Liter1, $LiterAuswahlFeld1, $AB1, $Raten1, $ortwert, $Oel1, $vkp);
//Ausgabe für Rechnung
$ergebnissRechnung1 = '"Rechnung1": true, "Liter1": "'.$rechnung1['Liter'].'", "Entfernung1": "'.$rechnung1['Entfernung'].'", "Richtwert1": "'.$rechnung1['Richtwert'].'", "PpLnetto1": "'.$rechnung1['PpLnetto'].'", "PpLbrutto1": "'.$rechnung1['PpLbrutto'].'", "Gesamtpreis1": "'.$rechnung1['Gesamtpreis'].'"';
} else {
$ergebnissRechnung1 = '"Rechnung1": false';
}
//Rechnung 2
if(strlen($Liter2) > 0 && is_numeric($Liter2)) {
//Variablen Kontrolle
if($LiterAuswahlFeld2!=='Max. Betrag') {$LiterAuswahlFeld2="Liter";}
switch ($AB2) {
case 1;
case 2;
case 3;
case 4;
case 5;
case 6;
case 7;
case 8;
break;
default:
$AB2=1;
break;
}
switch ($Raten2) {
case 1:
$Raten2=0;
break;
case 2:
$Raten2=1;
break;
case 3;
$Raten2=2;
break;
default:
$Raten2=0;
break;
}
if($Oel2!=='Premium Heizöl') {$Oel2="Heizöl EL";}
//Werte berechnen
$rechnung2=preisrechner($Liter2, $LiterAuswahlFeld2, $AB2, $Raten2, $ortwert, $Oel2, $vkp);
//Ausgabe für Rechnung
$ergebnissRechnung2 = '"Rechnung2": true, "Liter2": "'.$rechnung2['Liter'].'", "Entfernung2": "'.$rechnung2['Entfernung'].'", "Richtwert2": "'.$rechnung2['Richtwert'].'", "PpLnetto2": "'.$rechnung2['PpLnetto'].'", "PpLbrutto2": "'.$rechnung2['PpLbrutto'].'", "Gesamtpreis2": "'.$rechnung2['Gesamtpreis'].'"';
} else {
$ergebnissRechnung2 = '"Rechnung2": false';
}
//Rechnung 3
if(strlen($Liter3) > 0 && is_numeric($Liter3)) {
//Variablen Kontrolle
if($LiterAuswahlFeld3!=='Max. Betrag') {$LiterAuswahlFeld3="Liter";}
switch ($AB3) {
case 1;
case 2;
case 3;
case 4;
case 5;
case 6;
case 7;
case 8;
break;
default:
$AB3=1;
break;
}
switch ($Raten3) {
case 1:
$Raten3=0;
break;
case 2:
$Raten3=1;
break;
case 3;
$Raten3=2;
break;
default:
$Raten3=0;
break;
}
if($Oel3!=='Premium Heizöl') {$Oel3="Heizöl EL";}
//Werte berechnen
$rechnung3=preisrechner($Liter3, $LiterAuswahlFeld3, $AB3, $Raten3, $ortwert, $Oel3, $vkp);
//Ausgabe für Rechnung
$ergebnissRechnung3 = '"Rechnung3": true, "Liter3": "'.$rechnung3['Liter'].'", "Entfernung3": "'.$rechnung3['Entfernung'].'", "Richtwert3": "'.$rechnung3['Richtwert'].'", "PpLnetto3": "'.$rechnung3['PpLnetto'].'", "PpLbrutto3": "'.$rechnung3['PpLbrutto'].'", "Gesamtpreis3": "'.$rechnung3['Gesamtpreis'].'"';
} else {
$ergebnissRechnung3 = '"Rechnung3": false';
}
//Rückgabe
$ergebniss= '{"success": true, '.$ergebnissRechnung1.', '.$ergebnissRechnung2.', '.$ergebnissRechnung3.'}';
echo $ergebniss;
} else {
header('HTTP/1.1 400 Bad Request', true, 400);
echo "Der Name und die Literanzahl von wenigstens einer Rechnung muss ausgefüllt sein.";
}
} else {
header('HTTP/1.1 400 Bad Request', true, 400);
echo "Etwas ist seltsam!";
}
} else {
header('HTTP/1.1 400 Bad Request-1', true, 400);
echo "Das Feld darf nicht leer sein!";
}
?>
Thanks for all helping!
You have json - a string - and not a javascript object.
You need to parse it manually or tell jQuery that you expect json back so that jQuery can parse it automatically for you:
$.ajax({
type: "POST",
// tell jQuery you expect json back
dataType: "json",
url: "post.php",
// etc.
Apart from that, you should not create json manually in your php script. Instead, build an array with the required data structure and use json_encode($your_data_structure) at the end to encode it correctly.
hi i have an ajax request where i am sending some request to an php file through ajax and the request is generating a result so far everything is working good but now i want to keep some validations for my results. i am doing this on dynamically added table rows so if the validations is are not met it wont allow to add a new row but still after validating it is adding rows can anybody help in fixing my issue thanks
here is my code
$("#savetodb").removeAttr("disabled");
var vendor = $("#sub_vendor_id"+rowcount+">option:selected").val();
var product = $("#prodid_"+rowcount).val();
var productname = $("#prod_"+rowcount).val();
var vouchdt = $("#dateinfo").val();
var qty = $("#quantity_"+rowcount).val();
var amt = $("#amount_"+rowcount).val();
$.get("../model/check_product_with_invoice_number.php", { invno : invoice, product : product, vendor : vendor, date : vouchdt, quantity : qty, amount : amt }, function (result) {
if(result == "") {
alert(productname+" Does not exist for invoice number "+id);
$("#savetodb").attr("disabled", "disabled");
}
if(result == 2) {
alert("Quantity "+ qty +" for "+productname+" does not exist for invoice number "+id);
$("#savetodb").attr("disabled", "disabled");
}
if(result == 3) {
alert("Amount "+amt +" For "+productname+" does not exist for invoice number "+id);
$("#savetodb").attr("disabled", "disabled");
}
if(result !=='' && result !==3 && result !==2){
$("#savetodb").removeAttr("disabled");
append_row('enable remove','',prods,unitid,unitcode);
}
});
here is my php
$code = mysql_real_escape_string($_GET["invno"]);
$vendor = mysql_real_escape_string($_GET["vendor"]);
$product = mysql_real_escape_string($_GET["product"]);
$vouchdt = mysql_real_escape_string($_GET["date"]);
$amt = mysql_real_escape_string($_GET["amount"]);
$qty = mysql_real_escape_string($_GET["quantity"]);
$chkquantity = mysql_query("SELECT * FROM `gc_procurement_daily_detail` WHERE quantity_procured='".$qty."'
AND product_id='".$product."' AND sub_vendor_id='".$vendor."'")or die(mysql_error());
if(mysql_num_rows($chkquantity)> 0){
$chkamt = mysql_query("SELECT * FROM `gc_procurement_daily_detail` WHERE procured_detail_amount='".$amt."'
AND product_id='".$product."' AND sub_vendor_id='".$vendor."' AND quantity_procured='".$qty."'")or die(mysql_error());
if(mysql_num_rows($chkamt)>0){
$chkinvoice = mysql_query("SELECT a.*, b.* FROM `gc_procurement_daily_detail` a, `gc_procurement_daily_summary` b
WHERE a.sub_vendor_id='".$vendor."' AND a.product_id='".$product."' AND
a.quantity_procured='".$qty."' AND a.procured_detail_amount='".$amt."' AND
b.`date_of_invoice`='".$vouchdt."' AND b.invoice_number='".$code."' AND
a.`procurement_daily_summary_id`= b.procurement_daily_summary_id")or die(mysql_query());
$minv = mysql_fetch_object($chkinvoice);
$fininv = $minv->invoice_number;
if($code == $fininv){
echo 1;
exit;
}else{
echo '';
exit;
}
}else{
echo 3;
exit;
}
}else{
echo 2;
exit;
}
Ok just warp the ajax conditions inside double quote
if(result !=='' && result !=="3" && result !=="2")
And this for all of them.
as this answer has been chosen as best answer
i would suggest to combine other ideas also that you should chain your conditions in
if(){
}else if(){
}
an so on or use
Switch (result){
case 1:
//Do logic of this case here
break;
case 2:
//Do logic of this case here
break;
}
so you will have benefit of exiting execution whenever your condition achieved
That's all.
for the js part, you could use a switch for this:
switch(result){
case 2 : //error break;
case 3 : //error break;
case 4 : //error break;
default: //save stuff break;
}
Use a switch statement instead, like so:
switch(result){
case '':
alert(productname+" Does not exist for invoice number "+id);
$("#savetodb").attr("disabled", "disabled");
break;
case '2':
alert("Quantity "+ qty +" for "+productname+" does not exist for invoice number "+id);
$("#savetodb").attr("disabled", "disabled");
break;
case '3':
alert("Amount "+amt +" For "+productname+" does not exist for invoice number "+id);
$("#savetodb").attr("disabled", "disabled");
break;
default:
$("#savetodb").removeAttr("disabled");
append_row('enable remove','',prods,unitid,unitcode);
break;
}
Your result is probably coming back as a string not an integer so you will probably need to wrap the numbers with quotes.
I am developing a wordpress theme and now I am working on the theme options page. I added an option with "select" method to give the user the option to change the slider's fx. Now... this is the output of a text input that sets the fx duration <?php echo get_option('wis_fx_speed'); ?> and works fine! My problem is that <?php echo $fxSample ?> don't work.
Tried everything I knew and imagined (syntax, order, put the switch inside the jquery script etc) , searched the web but found nothing... Could you help me? Thanks in advance!
<?php
switch (get_option('wis_fx_slider')) {
case "opacity":
$fxSample = "opacity : 'toggle',";
break;
case "width":
$fxSample = "width : 'toggle',";
break;
case "opawidth":
$fxSample = "opacity : 'toggle', width : 'toggle',";
break;
case "blink":
$fxSample = "opacity : 'show',";
break;
}
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$("#photo-rotator").tabs({fx:{<?php echo $fxSample ?>
duration: <?php echo get_option('wis_fx_speed'); ?> }}).tabs("rotate", 2000);
});
</script>
OUTPUT:
<
script type="text/javascript">
jQuery(document).ready(function($){
$("#photo-rotator").tabs({fx:{ duration: 3000 }}).tabs("rotate", 2000);
});
</script>
EDIT
Works if I make it with radio.
When I need to pass some data to JavaScript, I find it helpful to build a PHP array first, then use json_encode to convert it to JavaScript. This avoids a lot of potential issues:
<?php
$tab_options = array(
'duration' => get_option('wis_fx_speed'),
'fx' => array()
);
switch (get_option('wis_fx_slider')) {
case 'opacity':
$tab_options['fx']['opacity'] = 'toggle';
break;
case 'width':
$tab_options['fx']['width'] = 'toggle';
break;
case 'opawidth':
$tab_options['fx']['opacity'] = 'toggle';
$tab_options['fx']['width'] = 'toggle';
break;
case 'blink':
$tab_options['fx']['opacity'] = 'show';
break;
}
?>
<script type="text/javascript">
var tabOptions = <?php echo json_encode($tab_options); ?>;
jQuery(document).ready(function($) {
$('#photo-rotator').tabs(tabOptions).tabs('rotate', 2000);
});
</script>
Benefits:
Much cleaner code (easier to read).
You don't have to worry about getting the commas, quotes, and other syntax right for all the possible cases. For example, as other people have mentioned, you don't have a default case. This approach will at least generate valid JavaScript if an option value is invalid.
To safely output any PHP value into a JavaScript value, use json_encode.
...{fx:<?php echo json_encode($fxSample); ?>, duration: <?php echo json_encode(get_option("wis_fx_speed")); ?>}...
Note also that you are missing a , and have an extra } in your code. Always look at the generated result to look for syntax errors.
You need a semicolon after each php line
...
$("#photo-rotator").tabs({fx:{<?php echo $fxSample; ?>
...
What about a default case value?
Try to debug doing a
var_dump(get_option('wis_fx_slider'));
var_dump($fxSample);
Maybe is it a scope problem? Try defining
$fxSample = "";
at the beggining, before the switch
Is get_option('wis_fx_slider') returning one of the options in the switch case?
You haven't sepcified a "default" so $fxSample will go undefined.
<?php
switch (get_option('wis_fx_slider')) {
case "opacity":
$fxSample = "opacity : 'toggle',";
break;
case "width":
$fxSample = "width : 'toggle',";
break;
case "opawidth":
$fxSample = "opacity : 'toggle', width : 'toggle',";
break;
default: // blink or anything else
$fxSample = "opacity : 'show',";
}
?>
Is your duration a string or number? If it's a string you need quotes like
duration: '<?php echo get_option('wis_fx_speed'); ?>' }}).tabs("rotate", 2000);
What happens when you view source? Is the PHP laying out the dynamically generated javascript correctly? Can you post the output?
Also, formatting
<?php
switch (get_option('wis_fx_slider')) {
case "opacity":
$fxSample = "opacity : 'toggle',";
break;
case "width":
$fxSample = "width : 'toggle',";
break;
case "opawidth":
$fxSample = "opacity : 'toggle', width : 'toggle',";
break;
case "blink":
$fxSample = "opacity : 'show',";
break;
}
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$("#photo-rotator").tabs({
fx: {
<?php echo $fxSample ?>
duration: <?php echo get_option('wis_fx_speed'); ?>
}
}).tabs("rotate", 2000);
});
</script>
Hi i want to get values from PHP files and make them usuable like array.
I'm using jquery.
How should i format retriever and php file to retrieve them all.
PHP file: i used switch to retrieve 1 at time but this method sucks
<?php
ob_start();
session_start();
include('mysql_config.php');
$konto = $_SESSION['login'];
$temp=mysql_fetch_array(mysql_query("SELECT `curchar` FROM `users` WHERE `login`='$konto'"));
$id = $temp['curchar'];
$gracz=mysql_fetch_array(mysql_query("SELECT * FROM `chars` WHERE `id`='$id'"));
$gracz['max_pz']=94+($gracz['str']+$gracz['stm']*5);
$gracz['max_pe']=7.1-($gracz['str']*0.1)+$gracz['stm']+$gracz['int']*2;
$gracz['max_exp']=($gracz['lvl']*10)*25;
if ($gracz['max_exp'] <= $gracz['exp'])
{
$gracz['lvl']++;
$zostalo = $gracz['exp']-$gracz['max_exp'];
mysql_query("UPDATE `chars` SET lvl=lvl+1, stats=stats+3, exp='$zostalo' WHERE `id`='$id'");
$gracz['exp']=$zostalo;
$gracz['max_exp']=($gracz['lvl']*10)*25;
}
$lol=$_POST['name'];
switch ($lol) {
case 'pz':
echo $gracz['pz'];
break;
case 'max_pz':
echo $gracz['max_pz'];
break;
case 'pe':
echo $gracz['pe'];
break;
case 'max_pe':
echo $gracz['max_pe'];
break;
case 'max_exp':
echo $gracz['max_exp'];
break;
case 'str':
echo $gracz['str'];
break;
case 'dex':
echo $gracz['dex'];
break;
case 'int':
echo $gracz['int'];
break;
case 'stm':
echo $gracz['stm'];
break;
case 'stats':
echo $gracz['stats'];
break;
case 'exp':
echo $gracz['exp'];
break;
case 'lvl':
echo $gracz['lvl'];
break;
case 'mapa':
echo $gracz['mapa'];
break;
case 'x':
echo $gracz['x'];
break;
case 'y':
echo $gracz['y'];
break;
default:
echo "post jest pusty";
break;
}
ob_end_flush();
?>
JS file(retriever): Here's retriever to get 1 variable but it is using sync that cause browser lags i don't want it
function get_char_val(merk)
{
var returnValue = null;
$.ajax({
type: "POST",
async: false,
url: "char_info2.php",
data: { name: merk },
dataType: "html",
success: function(data)
{
returnValue = data;
}
});
return returnValue;
}
Use JSON. In your PHP file, just output:
echo json_encode($gracz);
And change your ajax handler to accept json data:
$.ajax({
type: "POST",
async: false,
url: "char_info2.php",
data: { name: merk },
dataType: "json",
success: function(data) {
// Use data.max_pz or whatever here
}
});