Jquery Ajax post to a php script on the same page as the html
I am building an admin page for my wordpress theme and i thought of posting my form content to a php script that is on my html page.The php script is used to insert and help in editing my form.Here is the script.
- <?php echo date('H:i:s'); ?>
- <html><title>Ajax Example</title>
- <head>
- <script type="text/javascript"
- src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js">
- </script>
- <script type="text/javascript">
- $(document).ready(function() {
- $("#main").on ("click", "#login", function(event){
- event.preventDefault();
- {
- $.ajax({
- type: "POST",
- url: "jp.php",
- data: $("#main").serialize(),
- success: function(){
- alert('lorem ipsum');
- }
- });
- }
- });
- });
- </script>
- </head>
- <body>
- <form method="post" action="" class="ajax" id="main">
- <input type="text" name="city" value="hello world" />
- <input type="submit" id="login" />
- </form>
- </body>
- </html>
Is it possible to post to self like so?.