Yes, there are lots of topics about this, but no one really posts the full code so I do not understand what to do. I would appreciate help. I am using some custom API (jqgrid) and will explain what some things do.
This is how it goes:
First there is a PHP function
$getUnitID = <<<getUnitID //This is how you start a javascript function in this API
function(rowid, selected)
{
var selr= null;
if(rowid != null){
selr = jQuery('#grid').jqGrid('getGridParam','selrow');
return selr;
} //All this does is give me a value based on a row I click. It works great.
}
getUnitID; // End of JS function
Now I know I need to execute some AJAX. But I don't know when or where or how. I know about reading the manual but that doesn't always help. I am still lost (it's been 3 hours). Here is what I gather should be the AJAX, but where does it go?
$.ajax({
type: "POST",
url: "webpage.php",
dataType: "json",
data: selr,
success: function(data) {
alert (data);
}
});
I don't know how to implement that AJAX call.
The final goal is to place the data from var "selr" into a simple php function such as $myVariable.
Thank you for the help and time.
This is how I've tried to combine
$getUnitID = <<<getUnitID
function(rowid, selected)
{
var selr= null;
if(rowid != null){
selr = jQuery('#grid').jqGrid('getGridParam','selrow');
//alert (selr);
return selr;
}
$.ajax({
type: "POST",
url: "getId.php",
dataType: "json",
data: {selr:selr},
success: function(data) {
alert (data);
}
});
}
getUnitID;
$grid->setGridEvent('onSelectRow',$getUnitID);
$pdfButton = array("#pager",array("caption"=>"Create PDF", "onClickButton"=>"js: function(){parent.location='/pdftkphp/example/download.php?id= ". 6 ." '}"));
And the seperate PHP page is just
<?php
$rId = $_POST["selr"];
echo $rId + "some ajax stuff";
?>