Problem with Ajax and capturing Data after bign submitted

Overthere
Overthere used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Marco GasiFreelancer
Top Expert 2010

Commented:
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?

Author

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 GasiFreelancer
Top Expert 2010
Commented:
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...
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Most Valuable Expert 2011
Top Expert 2016
Commented:
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.

Author

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.
Most Valuable Expert 2011
Top Expert 2016

Commented:
Does the function need a name, maybe?  How is it invoked?

Author

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

Author

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
Expert of the Year 2008
Top Expert 2008

Commented:
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

Author

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...
Expert of the Year 2008
Top Expert 2008

Commented:
>> 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]"

Author

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....
Expert of the Year 2008
Top Expert 2008
Commented:
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);

Author

Commented:
the example page is from their example - and you replace the "customerNumber" with your field..

Author

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...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial