JavaScript How to use ajax in PHP foreach? ajax foreach data,ajax foreach json data,ajax foreach loop

I have a form with two select html tags and an input submit. To populate the value of option tags and to display the equivalent values of selected option tag, I use PHP, please see snippet below.

Now, I want to use AJAX using JS to avoid the reloading of the browser when the user clicked the button. But I don't know how. Please help me

Here's the link

Snippet:

if(isset($_POST['mall_list'])){
    $mall_list= $_POST['mall_list'];
    $malls= $wpdb->get_results($wpdb->prepare("SELECT stores FROM tablename WHERE malls = '" . $mall_list. "' GROUP BY stores ORDER BY stores", OBJECT));

    echo '<div class="\record\">';
    foreach ($malls as $record){
        echo '<div>' . $record->stores . '</div>';
    }
    echo '</div>';

} elseif(isset($_POST['store_list'])){
    $store_list= $_POST['store_list'];
    $stores= $wpdb->get_results($wpdb->prepare("SELECT malls FROM tablename WHERE stores= '" . $store_list. "' GROUP BY malls ORDER BY malls", OBJECT));

    echo '<div class="\record\">';
    foreach ($stores as $record){
        echo '<div>' . $record->malls. '</div>';
    }
    echo '</div>';
}
Answer:1

if you want to post data through ajax jquery. this code work for you.

$( "form" ).submit(function( event ) {
        event.preventDefault();
           $.ajax({
                type: "POST",
                url: "your post url",
                data: $('#yourformname').serialize(),
                success: function (data)
                {
                }
            });
});
Answer:2

I would like to count values inserted into a form without refreshing the page. The below code works well if all of the inputs have "name='test'" set the same but I need name to be unique to process ...

I would like to count values inserted into a form without refreshing the page. The below code works well if all of the inputs have "name='test'" set the same but I need name to be unique to process ...

  1. jquery count input values
  2. how to count input values in javascript

In Aurelia application I have a "Rename" form with a single input <input ... value.bind="something.name" /> and two buttons: Save and Cancel. The same something object is already used in ...

In Aurelia application I have a "Rename" form with a single input <input ... value.bind="something.name" /> and two buttons: Save and Cancel. The same something object is already used in ...

I have a value from JavaScript: var customerID = document.getElementById("CustomerID").value; Now I want query the firstName, lastName from module data, based on that customerID variable. {...

I have a value from JavaScript: var customerID = document.getElementById("CustomerID").value; Now I want query the firstName, lastName from module data, based on that customerID variable. {...

  1. pass javascript variable to php
  2. pass javascript variable to html
  3. pass javascript variable to c#
  4. pass javascript variable to python
  5. pass javascript variable to razor
  6. pass javascript variable to php function
  7. pass javascript variable to flask
  8. pass javascript variable to url.action
  9. pass javascript variable to django
  10. pass javascript variable to css
  11. pass javascript variable to jinja2
  12. pass javascript variable to ruby
  13. pass javascript variable to django url
  14. pass javascript variable to sql query
  15. pass javascript variable to asp classic
  16. pass javascript variable to python flask
  17. pass javascript variable to another html page
  18. pass javascript variable to django template
  19. pass javascript variable to mvc controller
  20. pass javascript variable between pages

I want to use jQuery to look for some text and it exists I want to hide it. So if : Yes exists it should be hidden. HTML: <div class="listing_detail col-md-4"><strong>Living Room:</...

I want to use jQuery to look for some text and it exists I want to hide it. So if : Yes exists it should be hidden. HTML: <div class="listing_detail col-md-4"><strong>Living Room:</...

  1. hide search text in datatable
  2. jquery datatable hide search text box
  3. hide text search