Pass variable in Jquery

Asked

Viewed 58 times

1

I have a template, that has this javascript:

    var _latitude  = -22.0565972;
    var _longitude = -46.9794721;
	
    //var jsonPath   = 'assets/json/items.json';
	var jsonPath   = 'assets/json/items.php';


    // Load JSON data and create Google Maps

    $.getJSON(jsonPath)
        .done(function(json) {
            createHomepageGoogleMap(_latitude,_longitude,json);
        })
        .fail(function( jqxhr, textStatus, error ) {
            console.log(error);
        })
    ;

    // Set if language is RTL and load Owl Carousel

    $(window).load(function(){
        var rtl = false; // Use RTL
        initializeOwl(rtl);
    });

    autoComplete();

In which json is generated here:

<?php
	/******* Conexão com o bando de dados *******/
	include "../../Conexao/config.php";
	mysqli_select_db($config, $database_config);
	mysqli_set_charset($config,"utf8");
	/******* Conexão com o bando de dados *******/
	


	$sql_16_a = mysqli_query($config, "SELECT id, razao_social, latitude, longitude, rua FROM tb_empresas LIMIT 10") or die(mysqli_error($config));
											
	$return_arr = array();
										
	if(@mysqli_num_rows($sql_16_a) <= '0'){
	    echo "";
	}else{
		while($r_sql_16_a = mysqli_fetch_array($sql_16_a)){
											
			$row_array['id'] = $r_sql_16_a['id'];
            $row_array['title'] = $r_sql_16_a['razao_social'];
            $row_array['location'] = "Clínicos Gerais";
            $row_array['latitude'] = $r_sql_16_a['latitude'];
            $row_array['longitude'] = $r_sql_16_a['longitude'];
            $row_array['url'] = "item-detail.html";
            $row_array['type'] = $r_sql_16_a['rua'];
            $row_array['type_icon'] = "flaticon-medical-2";
            $row_array['rating'] = "4";
            $row_array['gallery'] = 
                [
                    "images/imagem_padrao.jpg"
                ];
            $row_array['date_created'] = "2014-11-03";
            $row_array['price'] = "<span>(19) 3652-36...</span> Ver telefone";
            $row_array['featured'] =  "0";
            $row_array['color'] =  "";
									
											
			array_push($return_arr,$row_array);
		}
	}
									
	echo $json_busca = '{ "data": '.json_encode($return_arr) . "}"; 
									
?>

I need to pass a variable to the items.php file.

It is possible?

1 answer

0


See the documentation of getJSON

$.getJSON( url, {
    variavel1: "123123",
    variavel2: "321321",
  })

Browser other questions tagged

You are not signed in. Login or sign up in order to post.