Link to home
Start Free TrialLog in
Avatar of Overthere
Overthere

asked on

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

Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

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?
Avatar of Overthere
Overthere

ASKER

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.
SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Does the function need a name, maybe?  How is it invoked?
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
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
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
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...
>> 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]"
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....
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the example page is from their example - and you replace the "customerNumber" with your field..
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...