www.webdeveloper.com
Results 1 to 4 of 4

Thread: Use of a PHP Function() as a url in Jquery

  1. #1
    Join Date
    Oct 2005
    Location
    Knoxville Tennessee
    Posts
    79

    Use of a PHP Function() as a url in Jquery

    how does one go about using a function as a URL in an Ajax form submission? In PHP I have a form wherein I use a function as the action

    Code:
    <form action="<?php echo insert()" method="POST" id="addmail">
    which works well. However, the form is submitted via Ajax and I need a method in which to use the same function above in the Ajax URL

    Code:
    $.ajax({
    		type: "POST",
            url: "insert()", <------
            data: data,
    do I have to use routing for this? I started out trying to use a class with a method within it to run this form. It became painfully obvious that I could not do that with straight PHP. I have a page in which I'm going to have several forms and I did not want to have to write a separate PHP script (php file) for each form, I really wanted to put them in a functions page.

    Thank you for your consideration

  2. #2
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    You could get the action of the form and use that as the url instead of trying to insert it into the js file. Something like the following (untested):

    Code:
    $.ajax({
       type: "POST",
       url: $('#addmail').attributes('action'),
    // etc...
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  3. #3
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    sorry... double post
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  4. #4
    Join Date
    Oct 2005
    Location
    Knoxville Tennessee
    Posts
    79
    Now that looks promising. Will check that out. Thank you

    I have a few things to work out here but I think you may have a winner here. Thank you ever so much
    Last edited by mrwilson; 12-14-2012 at 03:38 PM.

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
  •  
HTML5 Development Center



Recent Articles