0

I have jQuery AJAX function that returns HTML that display result in some few page page where i mention the class

What I want

I Want that result should display in separate file i.e(testsearch.php) present on the test site: kargal.in

My code :

$("#searchsubmit").on('click', function(event){
    var maincat = $('.country').val(),
        subcat1 = $('.city').val(),
        subcat2 = $('.third').val(),
        subcat3 = $('.fourth').val(),
        searchkey = $('.search_key').val();

    event.preventDefault();

    //if(maincat == "" || subcat1 == "" || subcat2 == "" || subcat3 == ""){
    if(maincat == ""){
        alert("Please select the main category.");
        return false;
    }

    $(".searchCnt").html('<div class="srchloader"><img src="<?php echo     site_url();?>/search_loading_img.gif"><br /> Loading...</div>');

    $.ajax({
        type: "GET",
        url: "<?php echo site_url();?>/ajax_city.php",
        data: {
            action: 'search',
            maincat: maincat,
            subcat1: subcat1,
            subcat2: subcat2,
            subcat3: subcat3,
            searchkey: searchkey,
        },
        cache: false,
        async: true,
        success: function(responsedata) {   
            $(".post-block-out").remove();

            if(responsedata != ""){                 
                $(".searchCnt").html(responsedata); 
            }
            else {
                $(".searchCnt").html('<div class="srchnoRec">No ads found.   </div>');
            }
        } 
    });
});
fernandosavio
  • 9,849
  • 4
  • 24
  • 34
Ram Ji
  • 7
  • 5
  • So what's the problem? How does the code fail? –  Feb 02 '17 at 11:21
  • Its Not Fail.. the Search Result should display in new separate file. kindly check in http://kargal.in – Ram Ji Feb 02 '17 at 11:25
  • What do you mean by "separate file"? A new tab? You are requesting content from the server, then putting it in a div. What exactly do you want to do instead? "display in a separate file" doesn't make _any_ sense. –  Feb 02 '17 at 11:27
  • now its display result in current page (url), I want that should display Search result in New tab with url of http://kargal.in/testsearch.php – Ram Ji Feb 02 '17 at 11:31
  • 1
    If you want that, you don't need AJAX. Just send the form the regular way using `target="_blank"` in `
    ` and ``.
    –  Feb 02 '17 at 11:34
  • Its not working... still Load in same page. For info. the result will display only where i mention
    in php file
    – Ram Ji Feb 02 '17 at 11:50
  • Did you actually *disable* the AJAX code you posted above? If I look at kargal.in, I can still see it. –  Feb 02 '17 at 11:56
  • maybe `window.open` works for you, an example [here](http://stackoverflow.com/a/5141926/521880) – ramabarca Feb 02 '17 at 11:57
  • @ramabarca No, don't. Why make this complicated, given how simple it is? –  Feb 02 '17 at 11:58
  • when i disable the code the sub category drop down fail to function.. – Ram Ji Feb 02 '17 at 12:00
  • You need to disable _only_ the click handler for "#searchsubmit", not your entire JS code. –  Feb 02 '17 at 12:03
  • You're almost there. Put "testsearch.php" as your `action`. –  Feb 02 '17 at 12:12
  • Whoops! Page Not Found. :-( – Ram Ji Feb 02 '17 at 12:18
  • You need the proper path. Where in your `public_html` folder is `testsearch.php` located? The `action` attribute works exactly like the `href` in a link. You need to state the proper relative path. –  Feb 02 '17 at 12:20
  • yes.. I think it work thank you @ChrisG.. – Ram Ji Feb 02 '17 at 12:47
  • No.. Its Return blank page .. :-( – Ram Ji Feb 02 '17 at 13:28

0 Answers0