Problem with Ajax and capturing Data after bign submitted

I have a small snippet of coding that uses  php and ajax.
I have created a Heredoc to capture and post the new posted data to another page.
I added an event, jqGridAddEditAfterSubmit, to my grid component (from phpgrid.com)
and it executes the heredoc but displays "undefined"  from the  alert(postData.CustomerId);
It displays my page me.php with no value in custNum.
I am developing locally, using Windows Pro 7, MS Sql Server, Express 8 and php 5.6
Can anyone help me resolve this problem?

$afterSubmit = <<<AFTERSUBMIT
function (event, status, postData)
{
    console.log(event); 
    console.log(status); 
    console.log(postData);
    alert(postData.CustomerId);
    $.ajax({ url: 'me.php',
        data: {custNum: postData.CustomerId}, 
        type: 'post',
        success: function(output) {
                    alert(output);
                }
        });
}
AFTERSUBMIT;

Open in new window

OverthereAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
I've never seen a php function within a heredoc notation... How the function is called? Does postData is correclty passed to the function? Can you show some more code?
OverthereAuthor Commented:
It is javascript within a heredoc. See this link: http://phpgrid.com/example/custom-event-handler/

 A event is added to the component which "listens" for the added event and then is suppose to execute the heredoc...that's all the code there really is other than the code to add the event.
Marco GasiFreelancerCommented:
I apologize: yes, for sure, it is javascript. Sorry, I don't know phpgrid. I'll download it to see if I can understand a bit better how it works: your function is identical to their example so something is going wrong somewhere else...
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Ray PaseurCommented:
Can you see the console.log messages?

See if this article is helpful.
http://www.experts-exchange.com/articles/10712/The-Hello-World-Exercise-with-jQuery-and-PHP.html

$.post() and $.ajax() with type:'post' should be about the same.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OverthereAuthor Commented:
Good point Ray!  I have viewed the window event, application and services log,  sql server log etc.
And haven't really found anything. I would think it log something.
Ray PaseurCommented:
Does the function need a name, maybe?  How is it invoked?
OverthereAuthor Commented:
Its a javascript that is contained in the heredoc  - $$afterSubmit  and I add an event to the grid component , see below. Adding the event allows me to tap into the event when it happens - in this case on the AddEditAfterSubmit to the grid. Which is the correct event because the row and primary key doesn't exist until after being submitted.
I also looked again, and found some errors in the window event log. I have attached them and if you would be as so kind as to look at them. And my php.ini?
And I have a DCOM error too - strange. Perhaps that too is causing problems?
I never checked the event log for this type of error  - never occurred to t me since things seemed to be okay etc.
Maybe they are causing the it not to execute??
Boy if it is, I will be happy but at the same time I just might go lay down in front of an 18 wheeler on I-10....LOL

  $dg->add_event("jqGridAddEditAfterSubmit", $afterSubmit);

Open in new window

 $dg->add_event("jqGridAddEditAfterSubmit", $afterSubmit);
Event-1-Screen.JPG
Event---4-Details.JPG
OverthereAuthor Commented:
Update - What I have finally found was the console was showing the response.text with the "id" empty. This accounts for the errors, AND  it makes sense.
But what I don't know is why the response.text has no id - the record does insert successfully into the database.
See attached screen shot.
Any thoughts on how to fix it??
Console-Error---5.JPG
hieloCommented:
Your second screenshot above suggests that you don't have the extension needed to interact with the database.  I don't know how you are connecting to the database, but my guess is that you are not doing error checking otherwise you would have caught this sooner.

To enable the extension, Refer to:
https://msdn.microsoft.com/en-us/library/cc296203(v=sql.105).aspx
OverthereAuthor Commented:
I have checked your link and I do have the right sql server dll installed in my php extensions directory and my php.ini file contains a line for the loading of it...
hieloCommented:
>> the record does insert successfully into the database.
I missed that part.  It is actually inserting (as in "INSERT INTO tablename..." and not "UPDATE tablename...") successfully, then the only way for you to get an auto_id is if you have a field defined to be auto_increment and immediately after the INSERT you execute a SELECT statement to retrieve the id.  So try executing either:
"SELECT SCOPE_IDENTITY() as [auto_id]"

or
"SELECT @@IDENTITY as [auto_id]"
OverthereAuthor Commented:
Just to clarify, I am using a grid component, which insert the record for me... and I am adding an event to their grid to capture the event of it. Take a look at this link, See this link: http://phpgrid.com/example/custom-event-handler/
and you will see what my heredoc is doing....
hieloCommented:
what does:
console.log(postData);

show?  The reason I ask is because the example page that you refer to uses alert(postData.customerNumber); but you are using alert(postData.CustomerId);

So inspect the output of:
console.log(postData);
OverthereAuthor Commented:
the example page is from their example - and you replace the "customerNumber" with your field..
OverthereAuthor Commented:
I am going to close out this question... I believe that the problem should be resolved by the developers of the grid component... thanks everyone for responding.
I also believe it has to XMLHttp response object as to being able to pull the data...although their example does not state as such, from viewing the example I would say it to be so...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.