Need some Help with javascript and php together. - Page 2
Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30

Thread: Need some Help with javascript and php together.

  1. #16
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    In jQuery .html() is a method, not a property/variable.
    Code:
    jQuery('#cont').html(send.responseText);
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  2. #17
    Senior Member
    Join Date
    Dec 2007
    Posts
    115
    Thank you Dalecosp, Changed that. Still no response in <div id=cont> What am I missing?

  3. #18
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    Quote Originally Posted by minifairy View Post
    Thank you Dalecosp, Changed that. Still no response in <div id=cont> What am I missing?
    Hard to say. Is the browser console saying anything?

    Also, make sure to debug your PHP 'server' ("show_pmts.php") ... feed it valid data using a browser or browser-like SW and make sure it's giving you the expected response apart from the AJAX.
    Last edited by dalecosp; 03-10-2017 at 04:56 PM.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  4. #19
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Contact Unit "Coping Mechanism"
    Posts
    22,534
    I recall jQuery also provides a way to deal with error responses from the server instead of silently dropping them on the floor. But even without that, as dalecosp suggests, the browser's dev tools would tell you what if anything the server is responding with.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  5. #20
    Senior Member
    Join Date
    Dec 2007
    Posts
    115

    Question

    For starters I want to thank everyone that is helping me on this. I really appreciate it.
    Ok the console says nothing at all. I don't have a mail server on my local machine so I commented out the actual mail bit instead echoing the content of the email as well as the email address sent message. I get nothing. The source of the page showing the script part is in the attached text file. As far as I can see it looks right. I could not get the forum to put it in the code quote blocks so I uploaded it as a text file attachment.

    the place where the response is supposed to show up
    HTML Code:
    <h3 class=org>Email Progress</h3>
    <div id=cont>Response here</div>
    I can send individual emails to the subroutine and it works fine here is a link that works. This is localhost but it works online too.
    HTML Code:
    http://localhost/artshow/show_pmts.php?p=eax1xaxHEDRMARS
    note the p= portion before the x is the case it is going to. ea is the case that either sets up the java script or sends the same info to the smail routine in the case of only one person. So when someone clicks the send all emails button it goes to the ea case which builds the javascript in the attached text file and puts out the page where the progress is supposed to show up. If only one person is sent to that case in this example HEDRMARS then it builds the info and sends it to the smail case in a header stmt.
    PHP Code:
    header("location: show_pmts.php?p=smailx".$sid."x".$type."xa&email=".$eml."&fees=".$fees."&se=y"); 
    near as I can tell the header stmt is identical to the ajax except for the addition of the &se=y which tells it that it is a single email so it can put in the headers that would already be there for the multiple emails.

    The single email works. The multiple does not. If I remove the comment from the mail stmt in the php on my localhost (remember no mail server locally) then I get warnings in my apache error log
    [Fri Mar 10 11:19:15 2017] [error] [client 127.0.0.1] PHP Warning: mail() [<a href='function.mail'>function.mail</a>]: Failed to connect to mailserver at &quot;localhost&quot; port 25, verify your &quot;SMTP&quot; and &quot;smtp_port&quot; setting in php.ini or use ini_set() in C:\\indigo\\website\\artshow\\show_pmts.php on line 644, referer: http://localhost/artshow/show_pmts.php?p=lx1
    for each email it should be sending in the for next loop of the java script. But not getting any response in the 'Response Here' location on the page.

    Think I've tried to look everywhere just no idea what I'm missing.
    Attached Files Attached Files
    Last edited by minifairy; 03-15-2017 at 12:35 PM. Reason: Want to add a thank you to people helping.

  6. #21
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    If the "console says nothing at all", there are a couple of things to note. One, apparently whatever JS you're using isn't throwing errors. That's good. Next, to do some debug tracing of your JS, add console.log() statements:

    Code:
    myObject.myFunction();
    console.log("I just did the myFunction!");
    If your PHP script is logging a failure to send mail on the localhost, and you understand why, that's good enough. Most development machines aren't running full-fledged SMTP (Mail) servers, and I assume yours isn't, so that's cool, right?

    You say "But not getting any response in the 'Response Here' location on the page." Can you verify that a response is being sent? This would typically be in the "network" section of the debug console, instead of the "console" itself: https://i.stack.imgur.com/cFuNP.png
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  7. #22
    Senior Member
    Join Date
    Dec 2007
    Posts
    115
    Right I figured if the email warning is happening it means its there and it should be responding to the screen as well.

    Couldn't get it to take a screen shot. But I took a pic with my phone. I'm using firefox. This is what it shows in the network bit.IMG_20170315_092659208_HDR.jpgIMG_20170315_092659208_HDR.jpg

    if I click on the individual email entries I get the echo'd email as well as the echo'd response but its not ending up on the page? Seems to me like it should work fine. [confused]

  8. #23
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    Ok, so you see the response in console? Run your JS in the console with the response you see. (and, just for the sake of saying so, perhaps you should quote the id of the "cont" div? I am really not sure if that's the problem, but document attributes SHOULD be in quotes as far as I can recall, and it's not unlike modern browser to refuse to do things you expect them to do when they've nitpicked a small issue like that.... "<div id='cont'>" ?)
    Last edited by dalecosp; 03-15-2017 at 02:16 PM.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  9. #24
    Senior Member
    Join Date
    Dec 2007
    Posts
    115
    Quote Originally Posted by dalecosp View Post
    Ok, so you see the response in console? Run your JS in the console with the response you see.
    I run the page do an inspect element on the page look in console refresh page it shows each of the GETs if I click on one it automatically switches over to network view. In the response pane I see the appropriate response (its not on the page though) Seems like its not coming back into the <div id=cont> for some reason? In the params pane I see the email and the fees that were sent over from the JS In the preview pane I see the appropriate response as it should appear on the page..... but it is not on the page.

    don't know what you mean by run your JS in the console with the response you see???
    Last edited by minifairy; 03-15-2017 at 02:21 PM.

  10. #25
    Senior Member
    Join Date
    Dec 2007
    Posts
    115
    I know what you mean about nit picking. I've tried <div id='cont'>Response here</div> <div id="cont">Response here</div> <div #cont>Response here</div> (just in case it was something weird in the JS part.)

    the JS part for that is
    jQuery('#cont').html(send.responseText);
    That is right isn't it? I also tried
    jQuery('cont').html(send.responseText);
    none of these have brought my responses to the screen, although from everything I know (which admittedly isn't much in this area) it seems like it should be working.

  11. #26
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    Quote Originally Posted by minifairy View Post
    I know what you mean about nit picking. I've tried <div id='cont'>Response here</div> <div id="cont">Response here</div> <div #cont>Response here</div> (just in case it was something weird in the JS part.)

    the JS part for that is That is right isn't it? I also tried

    none of these have brought my responses to the screen, although from everything I know (which admittedly isn't much in this area) it seems like it should be working.
    Hmm. You might be doing this too early. AJAX is "asynchronous", so what I'm thinking is that the responseText probably doesn't exist when the html() method is called. It would have to be placed into the callback function for the AJAX call, I think?
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  12. #27
    Senior Member
    Join Date
    Dec 2007
    Posts
    115
    Ok Great I have no idea how to do this. I've been trying to figure this out for myself really I have. I've gone through https://www.w3schools.com/jquery/default.asp looking at everything that remotely looks promising and none of it looks anything like what we have put together here. All of their expamples use buttons that the user has to click. They say all the jquery should be inside a $(document).ready(function(){ When I try to put the loop inside that it quits working totally.

    In their callback example they are nesting functions which seems a bit odd.

    I couldn't find any reference to the type of syntax you suggested. I sort of understand what we built here but no idea where to put this callback. does it go in this where you define send?
    send = jQuery.ajax("./show_pmts.php?p=smailx1x1xa&email="+eml[i]+"&fees="+fees[i]);
    with a function embedded after fees? or does it go in the bit
    jQuery('#cont').load(send.responseText);
    I'm sorry I'm lost. [Really confused]

  13. #28
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Contact Unit "Coping Mechanism"
    Posts
    22,534
    Quote Originally Posted by minifairy
    e. I've gone through ...w3schools....
    That might be one of your problems right there. Perhaps something more authoritative would be better? Say, http://learn.jquery.com/

    In their callback example they are nesting functions which seems a bit odd.
    Well, get used to that, because having functions as "first-class citizens" that can be stored in variables and passed as values to other functions is how a lot of stuff is done in JavaScript.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  14. #29
    Senior Member
    Join Date
    Dec 2007
    Posts
    115
    Thank you Weedpacket. I'll look at the link you provided and see if I can figure this out.

  15. #30
    Senior Member
    Join Date
    Dec 2007
    Posts
    115
    Weedpacket;11061237]That might be one of your problems right there. Perhaps something more authoritative would be better? Say, http://learn.jquery.com/

    Weedpacket thanks again for that link. It is very good information. I've not gotten the time to go all the way through it and figure it all out but it is very informative. Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •