Autocomplete gives 500: internal server er

QuestionsAutocomplete gives 500: internal server er
Don asked 5 years ago

Hi, I want to autocomplete the country name in the customer table when adding a new customer.

I have:

$col = array();

$col[“title”] = “Country”;

$col[“name”] = “country”;

$col[“formatter”] = “autocomplete”;

$col[“formatoptions”] = array(“sql”=>”SELECT country.Name as k, country.Name as v FROM dbo.Country”);
 

But when I start typing in the field then a message “500: Internal Server Error. Status: error” pops up.
I don’t want to have a select drop down but normal input field.
What am I doing wrong?
Thanks!

8 Answers
Abu Ghufran Staff answered 5 years ago

Check error detail in browser debugger (F12) -> Network tab -> Ajax response text.
It should display if there is error in your sql.

Let me know if not resolved and share screenshot as well.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Don answered 5 years ago

Well, my sql query in $col[“formatoptions”] is reading from a different table; if I make the autocomplete query to the same table as the grid is using then it works as expected. By querying to a different table I get this as soon as I punch the first character:

Error (https://imgur.com/a/q1Swr6L)

I liked the idea that I could fetch data for the autocomplete form a different table (like to autocomplete country name instead of having a quite annoying select).

Abu Ghufran Staff answered 5 years ago

Check ajax response tab for exact error like this:

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Don answered 5 years ago

Hi Abu, It’s empty cause it an internal 500 error (and HTTP 500 error code). Strangely enough there is nothing on the php errors log file neither on the Apache log file. I don’t know where else to look.

I’m now starting to suspect that a php module is missing, do you know all the required modules?

Abu Ghufran Staff answered 5 years ago

Is your link online somewhere where i can see.
I can also check remotely if you setup https://remotedesktop.google.com/

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Don answered 5 years ago

Sorry Abu, I waitted for the remote connection and then had to go.

but, look at this code:

$g->table = "dbo.Customers";
$col = array();
$col["title"] = "Name";
$col["name"] = "name";
$cols[] = $col;

$col = array();
$col["title"] = "Country";
$col["name"] = "country";
$col["formatter"] = "autocomplete";
// this fails with HTTP error 500:
$col["formatoptions"] = array("sql"=>"SELECT name as k, name as v FROM dbo.Country");
// this works OK:
$col["formatoptions"] = array("sql"=>"SELECT DISTINCT country as k, country as v FROM dbo.Customers");
$cols[] = $col;

Both SQL querys work as they should in the SQL server.

Anyways I’m not planning to use more time on this. Thanks.

Abu Ghufran Staff answered 4 years ago

Hello,

Apolgies for the delay. Just to log solution, By default autocomplete searches on the field specified in $col[“name”], which is ‘country‘ in your case and searching works as it is part of your autocomplete query: SELECT DISTINCT country as k, country as v FROM dbo.Customers.

If you use different sql query or table which don’t have above field, you should also specify search_on field.

$col[“formatoptions”] = array(“sql”=>”SELECT name as k, name as v FROM dbo.Country”, “search_on”=>”name”);

Hope it helps.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Don answered 4 years ago

Thanks Abu, you nailed it!

That “search_on” was the secret 😉

Your Answer

2 + 12 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?