How enable in php long query strings


#1

I did a Sudoku PHP7 Solver app with jQm -ajax-GET-queryString–>PHP-> solution
in XAMPP/localhost working but live server Not… i do Not know where the problem is… any hint ?
how enable in php long query strings… ?

ajax-processor.php?c00=0&c01=0&c02=0&c03=0&c04=0&c05=0&c06=0&c07=0&c08=0&c10=0&c11=0&c12=0&c13=0&c14=0&c15=0&c16=0&c17=0&c18=0&c20=0&c21=0&c22=0&c23=0&c24=0&c25=0&c26=0&c27=0&c28=0&c30=0&c31=0&c32=0&c33=0&c34=0&c35=0&c36=0&c37=0&c38=0&c40=0&c41=0&c42=0&c43=0&c44=0&c45=0&c46=0&c47=0&c48=0&c50=0&c51=0&c52=0&c53=0&c54=0&c55=0&c56=0&c57=0&c58=0&c60=0&c61=0&c62=0&c63=0&c64=0&c65=0&c66=0&c67=0&c68=0&c70=0&c71=0&c72=0&c73=0&c74=0&c75=0&c76=0&c77=0&c78=0&c80=0&c81=0&c82=0&c83=0&c84=0&c85=0&c86=0&c87=0&c88=0

#2

Alternatively rather using GET use POST in jQ .ajax — how submit a javascript array to php using Post…ajax ?
How receive this array in PHP side of server backend code?


#3

You could use JSON encoding to submit the array via Ajax.

Have a browse down this forum, there are some recent examples showing how to do that.


#4

What is the actual error you’re getting? I don’t think PHP cares about how long the query string is, but your web server (Apache, nginx) might.

Also, to shorten it, you want to get rid of all the cXX= in the query string, since it doesn’t really add anything. This would work as well:

ajax-processor.php?c=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

Then to get all values you would use explode(',', $_GET['c']);


#5

in jQuery Ajax how convert
var queryString = $(‘form’).serialize();
from GET data to POST data?
how change data?
method: "POST"
what else change???

        $("a[name='solve']").click(function (e) {
            
                e.preventDefault();
                e.stopPropagation();
            
            var queryString = $('form').serialize();

            $("div#solution").html("<div style='text-align:center;'><img src='processing.gif' /><br>Please wait...!!!</div>");

            $.ajax({
                url:"ajax-processor.php",  
                data: queryString,
                contentType: "html",
                method: "GET",
                success: function(response) {
                    $("div#solution").html(response);
                },
                error: function() {
                    $("div#solution").html("No Exist Solution Or Error!!!");                
                }
            });

        });

#6

Well let’s think about that one.


#7

IN OTHER WORDS this data can be as well as GET as POST??? >>>
var queryString = $(‘form’).serialize();
without any change ONLY
method: “GET”,
become
method: “POST",
???


#8

Serialize will render it as a URL string. So you can pass it to your form by tacking it into an object and decoding on the PHP end, or you can JSON format your form which takes a bit more code on the javascript side but standard form processing on the PHP side. So… take your pick?


#9

Can you provide jQuery code how
tacking it into an object
and
decoding in PHP using $_POST[‘data’];
???


#10

c00=0&c01=0&c02=0&c03=0&c04=0&c05=0&c06=0&c07=0&c08=0&c10=0&c11=0&c12=0&c13=0&c14=0&c15=0&c16=0&c17=0&c18=0&c20=0&c21=0&c22=0&c23=0&c24=0&c25=0&c26=0&c27=0&c28=0&c30=0&c31=0&c32=0&c33=0&c34=0&c35=0&c36=0&c37=0&c38=0&c40=0&c41=0&c42=0&c43=0&c44=0&c45=0&c46=0&c47=0&c48=0&c50=0&c51=0&c52=0&c53=0&c54=0&c55=0&c56=0&c57=0&c58=0&c60=0&c61=0&c62=0&c63=0&c64=0&c65=0&c66=0&c67=0&c68=0&c70=0&c71=0&c72=0&c73=0&c74=0&c75=0&c76=0&c77=0&c78=0&c80=0&c81=0&c82=0&c83=0&c84=0&c85=0&c86=0&c87=0&c88=0

with this console.log(queryString.split(’&’)); // become>>> // how past below as POST from jQuery to PHP ??

["c00=0", "c01=0", "c02=0", "c03=0", "c04=0", "c05=0", "c06=0", "c07=0", "c08=0", "c10=0", "c11=0", "c12=0", "c13=0", "c14=0", "c15=0", "c16=0", "c17=0", "c18=0", "c20=0", "c21=0", "c22=0", "c23=0", "c24=0", "c25=0", "c26=0", "c27=0", "c28=0", "c30=0", "c31=0", "c32=0", "c33=0", "c34=0", "c35=0", "c36=0", "c37=0", "c38=0", "c40=0", "c41=0", "c42=0", "c43=0", "c44=0", "c45=0", "c46=0", "c47=0", "c48=0", "c50=0", "c51=0", "c52=0", "c53=0", "c54=0", "c55=0", "c56=0", "c57=0", "c58=0", "c60=0", "c61=0", "c62=0", "c63=0", "c64=0", "c65=0", "c66=0", "c67=0", "c68=0", "c70=0", "c71=0", "c72=0", "c73=0", "c74=0", "c75=0", "c76=0", "c77=0", "c78=0", "c80=0", "c81=0", "c82=0", "c83=0", "c84=0", "c85=0", "c86=0", "c87=0", "c88=0"]


#11

Perhaps I am missing the point… I would be tempted to use AJAX to send a single key stroke character to the server for processing. After processing dynamically render the screen.

Edit:
I believe there is virtually no limit in using session variables.


#12

POST THIS in jQuery …how get in php ???

{
c00: 0,
c01: 0,
c02: 0,
c03: 0,
c04: 0,
c05: 0,
c06: 0,
c07: 0,
c08: 0,
c10: 0,
c11: 0,
c12: 0,
c13: 0,
c14: 0,
c15: 0,
.....
.....
}
        $.ajax({
            url:"ajax-processor.php",  
            data: JSON.stringify(result),
            contentType: "html",
            method: "POST",
            success: function(response) {
                $("div#solution").html(response);
            },
            error: function() {
                $("div#solution").html("No Exist Solution Or Error!!!");                
            }
        });
$_POST=json_decode( $_POST ); // do not working

for($i=0; $i<9; $i++) :
    
    for($j=0; $j<9; $j++) :
        $grid[$i][$j] = $_POST["c".$i."".$j];
    endfor;

endfor;

#13

What do you get if you

var_dump($_POST);

before you try to do anything with it?

Can you expand on that? Is it empty, not the correct format, does it give an error message?


#14
array(0) {
}

                $.ajax({
                    type: "POST",
                    url: "ajax-processor.php",
                    data: JSON.stringify(result), // result   // same 
                    //dataType: "json",
                    contentType: "html",
                    success: function (response) {
                        console.log(response);
                        $("div#solution").html(response);
                    }
                });

#15

OK. Where does result come from, and what is in it?


#16
        console.log(JSON.stringify(result));

before use result var getting

{“c00”:0,“c01”:0,“c02”:0,“c03”:0,“c04”:0,“c05”:0,“c06”:0,“c07”:0,“c08”:0,“c10”:0,“c11”:0,“c12”:0,“c13”:0,“c14”:0,“c15”:0,“c16”:0,“c17”:0,“c18”:0,“c20”:0,“c21”:0,“c22”:0,“c23”:0,“c24”:0,“c25”:0,“c26”:0,“c27”:0,“c28”:0,“c30”:0,“c31”:0,“c32”:0,“c33”:0,“c34”:0,“c35”:0,“c36”:0,“c37”:0,“c38”:0,“c40”:0,“c41”:0,“c42”:0,“c43”:0,“c44”:0,“c45”:0,“c46”:0,“c47”:0,“c48”:0,“c50”:0,“c51”:0,“c52”:0,“c53”:0,“c54”:0,“c55”:0,“c56”:0,“c57”:0,“c58”:0,“c60”:0,“c61”:0,“c62”:0,“c63”:0,“c64”:0,“c65”:0,“c66”:0,“c67”:0,“c68”:0,“c70”:0,“c71”:0,“c72”:0,“c73”:0,“c74”:0,“c75”:0,“c76”:0,“c77”:0,“c78”:0,“c80”:0,“c81”:0,“c82”:0,“c83”:0,“c84”:0,“c85”:0,“c86”:0,“c87”:0,“c88”:0}


#17

I think but could be wrong that the reason jQuery worked locally was because both client and server were local.

Before assuming and taking the large step to pass an extra 80 variables to the live server did you try passing two variables and ensuring the results were received, modified and returned? It is not straightforward as the following link highlights the problem of trying to pass a single extra variable:

https://www.webdeveloper.com/forum/d/237163-how-do-i-pass-php-multiple-variables-to-javascript-ajax

Assumption
The extra 80 variables derived from a Sudoku grid of 9x9 - 1 = 80


#18

also, I wouldnt send unset values (so no 0’s), and use Javascript to verify there are at least 17 numbers set [the minimum number of numbers required for a 9x9 sudoku to be solvable] before submitting.

But that’s me.


#19

POST do Not work localhost so Not tried live

GET work ONLY localhost but Not live

live js and php also are same server like localhost

I think tried one var pass and worked but Not working pass 80 vars neither local nor live on POST…well?
Needed approx how many seconds to pass 80 vars in POST… ?


#20

Passing 80 vars in a single post probably won’t be measurably slower than passing a single one. The overhead is at the server end, parsing them into individual variables.