1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP and Ajax for URL

Discussion in 'PHP' started by schandak2001, Apr 27, 2017.

  1. #1
    I have a Link/URL.

    I am looking forward to

    1) On Click, it will send an email and Update the Db , without refreshing the page 2) Change the Text of the Link and Change Url as a normal Text.

    Example :

    Url : Send Email. After Clicking : Send Email and Update Db Text after email and DB done : Informed.

    How to do this ?
     
    schandak2001, Apr 27, 2017 IP
  2. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #2
    You can't be more vague in your question?
    Here's the concept of AJAX for you.

    The onclick invokes a javascript function, lets say: send_email()
    The function sends a http request to a PHP or whatever scriptting language you use. (GET or POST parameters included)
    // POST
    ajaxRequest.open("POST", url, true);
    ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxRequest.send(q);

    // GET
    ajaxRequest.open("GET", url, true);
    ajaxRequest.send(q);

    url is the url of the php page which has code to handle the request
    Finally the php page outputs something.
    <?php echo "message sent"; exit; ?>

    This output is caught by the javascript function.
    response =ajaxRequest.responseText;

    Then you update your page with output
    document.getElementById("outputDivID").innerHTML = response;
     
    JEET, Apr 27, 2017 IP
    sarahk likes this.
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    If you are using jquery it's even easier. Have you used it or a different ajax library before?
    What you are trying to do is really easy and a really good opportunity to learn.
     
    sarahk, Apr 27, 2017 IP
    JEET likes this.
  4. Ashok Kumar Pachauri

    Ashok Kumar Pachauri Greenhorn

    Messages:
    1
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #4
    You Can Use it like onclick invokes a function sendMail() of Javascript and the function is as below
    HERE Note that sendMail.php is the file which will send the mail as well update the database and you have to define what will be done there as per your requirement. you have to echo the response in sendMail.php you want on the page from where you are clicking the element




    <script>
    function sendMail()
    {
    var emailID=$("#emailID").val(); // emailID should be defined as the id of the email field or
    // change it at both places accordingly
    $.ajax({
    url:"sendMail.php",
    type: "post",
    data:{emailID:emailID},
    success:function(output){
    $("#outPutDiv").html(output);
    }
    });
    }
    </script>
     
    Ashok Kumar Pachauri, Apr 28, 2017 IP
    JEET likes this.
  5. schandak2001

    schandak2001 Member

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #5
    Have you used it or a different ajax library before? : No.
    You Can Use it like onclick invokes : How to Invoke it ?
     
    schandak2001, May 1, 2017 IP