3

It takes me a few paragraphs to explain this problem. I apologize for any inconvenience this may have caused you. I tried hard and researched a lot to solve the following problems, but so far I couldn't find solutions.

I am working on a directory creation project (using php, mysql, ajax and jquery) and currently I am stuck due to .htaccess URL rewrite issue (url rewrite / pretty url). I am using dependent dropdown on the home page for the search. The first dropdown is created using php and mysql and the dependent dropdown is created based on the selection on first dropdown using mysql, jquery and ajax. For example if, I select the country in the first dropdown then the related states get listed in the dependent dropdown. Then, once I hit the search button (in index.php page) it goes to the search result page (search.php).

Also, I have the same search dependent dropdown code on the top of the search.php file, so the users are able to search when they are in this page. Each of the results on the search.php page has links to go to moreinfroamtion.php where users can see more information about the selected item. I have placed the same search dependent dropdown code on the top of the moreinfroamtion.php file, so the users are able to search when they are in this page and if they make such searches, then the y are going to see the results in search.php page.

I am using GET method in the form and everything was working fine before implementing the url rewrite/pretty url process through .htaccess file. Once I upload the .htaccess file with url rewrite/pretty url code in it, everything works fine when I do the dependent dropdown search in index.php file (URL gets rewrite in search.php page From: exampletesting.com/TopTwo/search.php?country=Usa&state=New+York To: exampletesting.com/TopTwo/Jobs/Usa/New+York).

However, the issue is when I do a dependent dropdown search from this page (exampletesting/TopTwo/jobs/Usa/New+York) it gives the correct database results but displaying the following url on the address bar: http://exampletesting.com/TopTwo/jobs/Usa/New+York?country=Usa&state=New+York (added the extra ?country=Usa&state=New+York to the end of url).

Also, when I click the link on a result on the result page for more information it brings me the following page without displaying any database results on the page: http://exampletesting.com/TopTwo/Jobs/Driver/moreinfroamtion.php?description=Uber

I tried to place multiple rules in the same .htaccess to rewrite url/pretty url for the moreinformation.php file, but that didn't work. I also perform dependent dropdown search from this page (exampletesting.com/TopTwo/Jobs/Driver/moreinfroamtion.php?description=Uber) and it gives the database results but displaying the following url on the address bar: exampletesting.com/TopTwo/jobs/Usa/New+York?country=Usa&state=New+York (added the extra ?country=Usa&state=New+York to the url).

I would really appreciate if you guys can help me to resolve the above issues.

Following is my .htaccess file.

RewriteEngine On
RewriteBase /TestTwo/

RewriteCond %{THE_REQUEST} /search\.php\?country=([^&]+)&state=([^\s&]+) [NC]
RewriteRule ^ jobs/%1/%2? [R=301,L]

RewriteRule ^jobs/([^/]+)/([^/]+)/?$ search.php?country=$1&state=$2  [QSA,L,NC]

Following is the jquery/ajax code:

$(document).ready(function()
{
    $("#category").change(function()
    {
    var id=$(this).val();
    var data = 'id='+ id;

    $.ajax
    ({
    type: "POST",
    url: "http://exampletesting.com/TestTwo/states.php",
    data: data,
    cache: false,
    success: function(html)
   {
      $("#states").html(html);
   } 
   });
  });

});
E. Edgo
  • 49
  • 4
  • Have you checked your console log? Not sure what browser you're using or what you're using to debug your ajax requests, What browser are you using? – beingalex Apr 28 '16 at 22:14
  • "but displaying the following url on the address bar: http://exampletesting.com/TopTwo/jobs/Usa/New+York?country=Usa&state=New+York (added the extra ?country=Usa&state=New+York to the end of url)" tells me that your javascript is throwing an error. – beingalex Apr 28 '16 at 22:17
  • What code is inside `http://exampletesting.com/TestTwo/states.php`? It could be an issue with the HTML coming from there. Is there any relevant html from the dropdown? The more information the better. – shamsup Apr 28 '16 at 22:20
  • Thank you for the reply everyone. I am using Firefox browser. This is the code in the states.php: – E. Edgo Apr 28 '16 at 22:35
  • BTW http://exampletesting.com/TestTwo/states.php in the jquery/ajax code is actually http://exampletesting.com/TopTwo/states.php (the directory is TopTwo not TestTwo. I have typed it incorrectly when posted it here. I am sorry about that. The issue could be related to javascript and/or HTML. I spent so many hours on this issue, but still couldn't figure out what the issue is. – E. Edgo Apr 28 '16 at 22:55
  • @ShamSUP following is the form which includes dependent dropdown:
    – E. Edgo Apr 29 '16 at 00:15

0 Answers0