Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6075207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:28:07+00:00 2026-05-23T10:28:07+00:00

Hey I got a working jquery post function, but it’s still not working as

  • 0

Hey I got a working jquery post function, but it’s still not working as I want it to work. The var “url” should be a an url as in the regex pattern below, when it matches the regex pattern jquery should post a request with the url in it to my php file, after that it will return a unique ref id and rewrite the url to a new one on my own site like example.org/ref.php?id=unique1235 (the url rewrite/replace with unique generated string from php script works already perfectly.)

My JQuery function looks like this:

    $(".url2").keyup(validNum).blur(validNum);

    var refid;

    var url;  // needs to be extracted from the live input textarea with the pattern below that is used to replace the old url with the new one coming from the post php script

    $.ajax({                     url: "/test.php",
                                 data: {
                                 url: url
                                 },
                                 type: "POST",
                                 success:function(returnID) {
                                 refid = returnID 
                                     }
                                });




    function validNum() {
     var initVal = $(this).val();
    outputVal = initVal.replace(/(https?:\/\/)?(www.)?[0-9A-Za-z-]{2,50}\.[a-zA-Z]{2,4}([\/\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#]){0,250}(\s){1}$/
,refid);  
    if (initVal != outputVal) {
        $(this).val(outputVal);
        return false;
        }}
});

I’m unable to “live”-extract the url from my textarea and save it to “var url” so that it can be passed and send to the php script where the old url gets saved and replace by an unique string (as described above). Would be so glad if someone is able to help me. Thanks alot 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:28:08+00:00Added an answer on May 23, 2026 at 10:28 am

    The problem is that you’re triggering the $.ajax() directly, it’s like “Everytime the document loads, that empty request loads, and it doesn’t load more”. Put it on a function, like this:

       function request_my_URL(){
              var refid;
               var url=$('.url2').val();      
               $.ajax({              url: "/test.php",
                                     data: {
                                     url: url
                                     },
                                     type: "POST",
                                     success:function(returnID) {
                                     refid = returnID;
                                     alert(refid);
                                         }
                                    });
       }
    

    Now, call the function in the click event of some button, for example:

       <textarea class='url2'></textarea>
       <input type='button' value='Get the URL!' onClick='request_my_URL();' />
    

    It’s your turn to modify this to work as you expect 😀

    Good Luck 😉

    EDIT:

    For live checking, you can use this:

    $(".url2").keyup(function(){validNum(); request_my_URL();}).blur(function(){validNum(); request_my_URL();});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I've got Lampp installed in Ubuntu and I want to get .htaccess working
Hey! First post for me but long time reader of Stackoverflow. Anyway, got a
Hey guys I've finally got my google maps working the way I want it,
Hey I'm trying to get this working but I am not a c# programmer.
Hey guys, so I've got my NSFetchedResultsController working fine under the 3.1 SDK, however
hey everyone... so i'm working on a database design class for university. I've got
Hey I got the following ps for retrieving the site template from SharePoint,but I
Hey there, working on the code and kind of got it working. Now pleeaseee
Hey guys, I've got what I imagine is a simple question, but for some
Hey. I've got a dumb, but nasty problem. If I've got this (simplified) situation:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.