在发送到服务器之前获取URL参数?

时间:2018-08-22 01:45:03

标签: javascript

是否可以从URL获取所有参数? 例如,在<div id="men_product" style=""> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <div class="container"> <div class="row"> <div class="col-12 col-md-8"> <div class="transbox"> <img src="images/9img.jpg"> </div> <!-- /transbox --> </div> <!-- /col-md-6 --> <div class="col-6 col-md-4"> <div class="carousel slide" id="carouselExampleControls4" data-ride="carousel"> <div class="text-md-right"> <a class="carousel-control-prev" href="#carouselExampleControls4" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselExampleControls4" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden= "true"></span> <span class="sr-only">Next</span> </a> </div> <!-- /carousel-button --> <div class="carousel-inner"> <div class="carousel-item"> <div class="row"> <div class="col-md-3"> <a href="#" class="thumbnail"> <img src="images/3img.jpg" alt="Image" style="max-width:100%;"> <div class="text_box"> <h4 class="hidedesktop">Christmas Clothes</h4> <div> <span class="price pull-left"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>300.00</span></span> </div> </div> </a> <a href="" data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="352" data-product_sku="" aria-label="Add &ldquo;Christmas Clothes&rdquo; to your cart" rel="nofollow">Add to cart</a> </div> <div class="col-md-3"> <a href="#" class="thumbnail"> <img src="images/3img.jpg" alt="Image" style="max-width:100%;"> <div class="text_box"> <h4 class="hidedesktop">Christmas Clothes</h4> <div> <span class="price pull-left"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>300.00</span></span> </div> </div> </a> <a href="" data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="352" data-product_sku="" aria-label="Add &ldquo;Christmas Clothes&rdquo; to your cart" rel="nofollow">Add to cart</a> </div> </div><!-- END ROW --> </div> <!-- /item --> <div class="carousel-item"> <div class="row"> <div class="col-md-3"> <a href="#" class="thumbnail"> <img src="images/3img.jpg" alt="Image" style="max-width:100%;"> <div class="text_box"> <h4 class="hidedesktop">Christmas Clothes</h4> <div> <span class="price pull-left"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>300.00</span></span> </div> </div> </a> <a href="" data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="352" data-product_sku="" aria-label="Add &ldquo;Christmas Clothes&rdquo; to your cart" rel="nofollow">Add to cart</a> </div> <div class="col-md-3"> <a href="#" class="thumbnail"> <img src="images/3img.jpg" alt="Image" style="max-width:100%;"> <div class="text_box"> <h4 class="hidedesktop">Christmas Clothes</h4> <div> <span class="price pull-left"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>300.00</span></span> </div> </div> </a> <a href="" data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="352">Add to cart</a> </div> </div><!-- END ROW --> </div> <!-- /item --> </div> <!-- /carousel-inner --> </div> <!-- /carousel --> </div> <!-- /col-sm-6 --> </div> <!-- /row --> </div> <!-- /container --> </div> <!-- /col-md-12 --> </div> <!-- /row --> </div> <!-- /men-container -->

输入所有必需信息并按“搜索”(公共汽车)按钮时,是否可以检索发送到服务器的URL地址中的所有参数(查询)?

2 个答案:

答案 0 :(得分:0)

我不确定您要完成什么。您的问题中没有足够的信息。 但是我假设您只想获取给定URL的所有部分。

如果是这样,您可以轻松地使用php,例如提取URL的最后一部分:

$data = json_decode($response, true);

// die('<pre>'.print_r($data, true).'</pre>');

foreach($data['events'] as $key => $item) {

    // $event_id = $data['events'][$key]['eventId'];
    $event_id = $item['eventId'];

    // $name = $data['events'][$key]['name'];
    $name = $item['name'];

    // $desc = $data['events'][$key]['description'];
    $desc = $item['description'];

    echo "KEY: $key, ID: $event_id, NAME: $name, DESCRIPTION: $desc";
}

答案 1 :(得分:0)

我想知道该表格的所有可能参数