jQuery Ajax call

Sample jQuery Ajax Call-1:

—————————————————————————————————-

<script type=”text/javascript”>

var productid = jQuery(‘#product_id’).val();

jQuery.ajax({
type: “POST”,
url: “<?php echo home_url(); ?>/wp-content/plugins/dynamic-search-form/search_products.php”,
data: {prod_id: productid },
dataType:’json’,
success: function (data) {
console.log(data);
},
error : function(s , i , error){
console.log(error);
}

});

</script>

Php Code: (search_products.php)

<?php  require_once(‘../../../wp-blog-header.php’);
if($_POST){
global $table_prefix,$wpdb;

$prod_id = $_REQUEST[‘prod_id’];
$sql = “select * from “.$table_prefix.”pc_products where product_id=”.$prod_id;
$result = $wpdb->get_results($sql);
echo json_encode($result);
die();
}

———————————————————————————————

Sample jQuery Ajax Call – 2:

<script type=”text/javascript”>

var productid = jQuery(‘#product_id’).val();

jQuery.ajax({
type: “POST”,
url: “<?php echo home_url(); ?>/wp-content/plugins/dynamic-search-form/search_product_price.php”,
data: {prod_id: productid },
success: function (data) {
console.log(data);
},
error : function(s , i , error){
console.log(error);
}

});

</script>

Php Code: (search_product_price.php)

<?php  require_once(‘../../../wp-blog-header.php’);
if($_POST){
global $table_prefix,$wpdb;

$prod_id = $_REQUEST[‘prod_id’];
$sql = “select price from “.$table_prefix.”pc_products where product_id=”.$prod_id;
$result = $wpdb->get_results($sql);
echo $result[0]->price;
}

———————————————————————————————–

1 Comment

  • mocler

    March 30, 2014 at 9:41 am Reply

    Does уour site have a contact page? I’m hɑving trouble locating
    it but, I’d like to send you an email. I’ve got some ideas
    for your blog you might ƅbe interested in hearing. Either way, great sіte
    and I loiok forward to seeing it expand over time.

Post a Reply to mocler Cancel Reply