Monty Monty - 4 months ago 16
jQuery Question

Sending ID data with jQuery AJAX

I need to fetch my id and Edit the tables value..but i am not able to fetch id from database and actually i am trying to send it by this way....

$(document).on('submit', '#form_company.edit', function(e){
e.preventDefault();
// Validate form
if (form_company.valid() == true){
// Send company information to database
hide_ipad_keyboard();
hide_lightbox();
show_loading_message();
var id = $('#form_company').attr('data-id');
var form_data = $('#form_company').serialize();
var request =

$.ajax({
url: 'data.php?job=edit_company&id=' + id,
cache: false,
data: form_data,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
type: 'get'
});

`


but it is getting passed by URL ..i want to send it by "data:"..how to do it..

Answer

You can post both data in POST parameter like below:-

$.ajax({
  url:          'data.php',
  type:          'POST',
  cache:        false,
  data:         {'form_data':form_data,'job':'get_company','id': id} ,
  dataType:     'json',
  contentType:  'application/json; charset=utf-8',

});

And now in php (data.php):-

<?php
  echo"<pre/>";print_r($_POST);
?>

Note:- based on this printed data you can do your stuff accordingly. Thanks