0

I'm using jquery for form submission. For the form I'm using the following html:

   <form class="classform form-horizontal" id="id_name">
    ... 
    <button class="btn btn-success" type="button" id="buts_button">Save</button>
    </form>. 

in jquery I'm doing this:

    $(document).ready(function ()
    {
    $("#buts_button").click(function ()
    { 
    var data = $( "#id_name" ).val(); 
      var url = "name.php?Agt="+data+"
                $.post(url,function (data){
                  alert("Saved Successfully");
                  location.reload();
                 });
    });

If I click the button it is not showing the alert like "Saved Successfully". the value is coming in URL why?. in I'm not using the Get method also. can u help me?

Working jquery in same page

$(document).ready(function ()
     {
         $("#age_edit_btn").click(function (){
             var vst_id = $( "#vst_admin_id" ).val();
             var age_name = $( "#age_name" ).val();
             var agen_hall = $( "#age_hall" ).val();
             var url = "eve_home_controller.php?Age_edit="+vst_id+"&age_name="+age_name+"&age_hall="+age_hall);
             $.post(url,function (data){
                   alert("Updated Successfully");
             });              
         });
     });

Not working jquery in same page.

$(document).ready(function (){
         $("#spe_save").click(function (){
              var spe_data = "Spk_Rdy";
             var rate_eve_id = $( "#rate_eve_id" ).val();
             if(rate_event_id == "")
                 {
                    alert('Please select the event id');
                     $( "#rate_event_id" ).focus();
                     return false;
                 }
             var rate_age_id = $( "#rate_age_id" ).val();
             var spe_title = $("#spe_title").val();
             var spe_name = $("#spe_name").val();
             var spe_details = $("#spe_details").val();
             var url = "event_home_controller.php?Spk_Rdy="+spe_data+"&rate_eve_id="+rate_eve_id+"&rate_age_id="+rate_age_id+"&spe_title="+spe_title+"&spe_name="+spe_name+"&spe_details="+spe_details;
             $.post(url,function (data){
                 alert(data);
              alert("Saved Successfully");
              location.reload();
             });
         });
     });
Luke
  • 77
  • 8

3 Answers3

0

jQuery is not working properly, that's why you are seeing the URL

Captain Planet
  • 408
  • 3
  • 19
  • Thanks for your response. But in the same page i am posting form using jquery it is working perfect. if jquery problem means the hole page should not work know? – Luke Sep 17 '14 at 11:01
  • Hi, this code is working in same page. $(document).ready(function () { $("#age_edit_btn").click(function (){ var vst_id = $( "#vst_admin_id" ).val(); var age_name = $( "#age_name" ).val(); var agen_hall = $( "#age_hall" ).val(); var url = "eve_home_controller.php?Age_edit="+vst_id+"&age_name="+age_name+"&age_hall="+ag‌​e_hall); $.post(url,function (data){ alert("Updated Successfully"); }); }); }); – Luke Sep 17 '14 at 11:45
0

You have multiple errors in your script.

var url = "name.php?Agt="+data+"                        
$.post(url,function (data){
    alert("Saved Successfully");
    location.reload();
});

In the $.post you are posting to the url which you try to create. This is not going to work. Something that should work is this:

$.post('some_php_file.php', {Agt : data}, function (answer) {
    alert("Saved Successfully");
    var url = "name.php?Agt="+answer; 
    // or window.location.href("name.php?Agt="+answer); //This will go to that name.php page
});

Now you post $_POST['Agt'] with the value of whatever is in the data variable to some_php_file.php. The answer you get will then be used as $_GET[] to name.php

UPDATE I hope this is what you need: I'll take the variable url from the part that doesn't work for you.

$.post(url, {data : data}, function(answer) {
   alert(answer);
   alert('Saved Successfully');
   location.reload();
});

So now you use the url variable to post the data variable values to. You can get the data values in the php file with: $_POST['data']. The first data is the name of the post. the second data is the value. The answer is what you get back from the php file. It is not the data what you try to send or need to send. this is why there is a answer in the function(answer)

UPDATE Or this:

$(document).ready(function() { 
    $("#age_edit_btn").click(function () { 
        var vst_id = $( "#vst_admin_id" ).val(); 
        var age_name = $( "#age_name" ).val(); 
        var agen_hall = $( "#age_hall" ).val(); 
        var url = "eve_home_controller.php?Age_edit="+vst_id+"&age_name="+age_name+"&age_hall="+age_hall); 

        $.post(url, {data : data} function(data) {
            alert(data); // This is the data from the function(data) 
            alert("Updated Successfully"); 
        }); 
    }); 
}); 
SuperDJ
  • 7,488
  • 11
  • 40
  • 74
  • Thanks for your response. but i want the jquery like this. $(document).ready(function () { $("#age_edit_btn").click(function (){ var vst_id = $( "#vst_admin_id" ).val(); var age_name = $( "#age_name" ).val(); var agen_hall = $( "#age_hall" ).val(); var url = "eve_home_controller.php?Age_edit="+vst_id+"&age_name="+age_name+"&age_hall="+ag‌​e_hall); $.post(url,function (data){ alert("Updated Successfully"); }); }); }); – Luke Sep 17 '14 at 11:44
0
$.post('url',
  {Agt : data },
   function(data) {
       alert("Saved Successfully");
       location.reload();
});

You are using post and passing data in url not right way.

In your name.php get psted value:

$agt = $_POST['AGT'];

$(document).ready(function ()
     {
         $("#age_edit_btn").click(function (){
             var vst_id = $( "#vst_admin_id" ).val();
             var age_name = $( "#age_name" ).val();
             var agen_hall = $( "#age_hall" ).val();
             var url = "eve_home_controller.php";
             $.post(url,
                   {
                      Age_edit : vst_id,
                      age_name: age_name,
                      age_hall: age_hall,
                   }, 
                   function (data){
                   alert("Updated Successfully");
             });              
         });
     });

get above value in eve_home_controller.php same like name.php using $_POST

Your jQuery would be on same page where is your buttons. If not getting success alert it probably may problem in php file. Please see error by inspecting element. and post that error here.

herr
  • 837
  • 1
  • 8
  • 21
  • Thanks for your response. but i want the jquery like this. $(document).ready(function () { $("#age_edit_btn").click(function (){ var vst_id = $( "#vst_admin_id" ).val(); var age_name = $( "#age_name" ).val(); var agen_hall = $( "#age_hall" ).val(); var url = "eve_home_controller.php?Age_edit="+vst_id+"&age_name="+age_name+"&age_hall="+ag‌​e_hall); $.post(url,function (data){ alert("Updated Successfully"); }); }); }); – Luke Sep 17 '14 at 11:45