Solved

jQuery not sending serialized get on a 3rd AJAX request

Posted on 2014-03-26
12
648 Views
Last Modified: 2014-03-26
I am not sure why jquery is doing this but on a 3rd ajax request it is not sending any data (IE GET form data)

Page 1: A simple admin interface with a menu and a div on the side. Clicking on the menu calls another file that is rendered in the div.

Example:
<li><a href="admin_users.php?type=2" id="type2" ><span>&nbsp;Pending</span></a></li>


<div id="action_window"></div>

<script>
$(document).ready(function(){
	$("#type1").bind('click',function(event){
		event.preventDefault();
		$.get(this.href,{},function(response){
			$('#action_window').html(response)
		}) 
	});
        $("#type2").bind('click',function(event){
                event.preventDefault();
                $.get(this.href,{},function(response){
                        $('#action_window').html(response)
                })
        });
        $("#type3").bind('click',function(event){
                event.preventDefault();
                $.get(this.href,{},function(response){
                        $('#action_window').html(response)
                })
        });
        $("#type4").bind('click',function(event){
                event.preventDefault();
                $.get(this.href,{},function(response){
                        $('#action_window').html(response)
                })
        });
        $("#type5").bind('click',function(event){
                event.preventDefault();
                $.get(this.href,{},function(response){
                        $('#action_window').html(response)
                })
        });
        $("#type6").bind('click',function(event){
                event.preventDefault();
                $.get(this.href,{},function(response){
                        $('#action_window').html(response)
                })
        })



});
</script>

Open in new window


Page 2 - then admin_users.php?type=2 opens in the DIV and displays a list of users to edit. The 2nd screen uses another jquery bind event to call out:
<div id="action_window2">
<a id="view" href="edit_contact.php?id=5">View/Edit</a>
</div>


<script>

$(document).ready(function(){
        $("#contact").bind('click',function(event){
                event.preventDefault();
                $.get(this.href,{},function(response){
                        $('#action_window2').html(response)
                })
        });
        $("#view").bind('click',function(event){
                event.preventDefault();
                $.get(this.href,{},function(response){
                        $('#action_window2').html(response)
                })
        })

});



</script>

Open in new window


Page 3 then displays a form that the user can update:

Note: This is php below so I am using the \ as the escape key...
                <div id=\"contact_form\">
                <form name=\"myform2\" id=\"myform2\">
                <input type=\"hidden\" name=\"id\" id=\"id\" value=\"$_GET[id]\">

                just some input boxes.... 

<input type=\"button\" value=\"Save\" class=\"button1\" onclick=\"admin_update_candidate_contact(this.form)\">

                                 function admin_update_candidate_contact(myform2) {
                                        $.get('admin_update_candidate_contact.php',
                                        $(myform2).serialize(),
                                        function(php_msg) {
                                                $("#contact_form").html(php_msg);
                                        });
                                 }

Open in new window


When I click on the button the file admin_update_candidate_contact.php is called but nothing is sent. I did a foreach to print out the GET data and nothing is being sent.

Firebug displays the request as is always does when I press the button. I have always used just a 2 tier ajax system so this is a little different for me. If you need to see the website in action I can provide the URL, username and password. It's a staging area so there is no sensitive info there.
0
Comment
Question by:Robert Saylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
12 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39955688
yes, please provide the URL
0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39955704
http://pivot.customphpdesign.com/

username: admin
password: password

After you login, click "Pending" under candidates , then click on View/Edit for the test user.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39955725
Work fine for me.saved
On which browser are you testing?
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 7

Author Comment

by:Robert Saylor
ID: 39955738
Change a field. The message is sucess because the SQL query is valid.

       
SELECT `candidate_profile`.*, `contacts`.* FROM `candidate_profile`,`contacts` WHERE `candidate_profile`.`contactID` = '' AND `contacts`.`id` = ''

id should pass a value.
0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39955740
I am using firefox on Windows 8 and firefox on Mac. Both does the same.
0
 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 500 total points
ID: 39955752
It's not working because the HTML that contains your form is malformed. If I look at the source after loading in the contact form, you'll see this:

<div id="contact_form">
   <form id="myform2" name="myform2"></form>
   <input type="hidden" value="5" id="id" name="id">
   ...

Open in new window


You'll notice that the form is self closing with nothing in it, so when you click the button it has nothing to serialize. Sort out the HTML and you'll be good to go.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39955754
I changed addr2 I set with TEST, check
0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39955763
Thanks! I will give that a look in a few mins. I must have been dozing off while writing that lol.
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39955778
Just bear in mind, for valid HTML (particularly with tables) the only things that can go inside a TABLE tag are standard table elements (TR/TD/TH etc). You can't put DIV tags directly inside TABLE tags - they need to go into a TD or TH, and the only things that can go in TR tags are TH and TDs - if you get it wrong then a browser will try and close off tags that it thinks are left open, causing all sorts of problems.
0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39955785
yea it must be somewhere in my 3 files closing the form early. I will check it out. Odd the last file does not close it but I see firebug is showing it closed like you said now.

                <div id=\"contact_form\">
                <form name=\"myform2\" id=\"myform2\">
                <input type=\"hidden\" name=\"id\" id=\"id\" value=\"$_GET[id]\">
                <b>Contact: (First, Middle, Last)</b><br>
                <input type=\"text\" name=\"fname\" value=\"$fname\" size=20> <input type=\"text\" name=\"mname\" value=\"$mname\" size=10> <input type=\"text\" name=\"lname\" value=\"$lname\" size=20><br><br>
                <b>Address:</b><br>
                <input type=\"text\" name=\"addr1\" value=\"$addr1\" size=40><br>
                <input type=\"text\" name=\"addr2\" value=\"$addr2\" size=40><br>

                <br>City / State / Zip:<br><input type=\"text\" name=\"city\" value=\"$city\" size=20>, <select name=\"state_id\">$state2</select>, <input type=\"text\" name=\"zip\" value=\"$zip\" size=5><br><br>
                <b>Communications:</b><br>
                <table border=0 width=600>
                <tr><td width=150>Email:</td><td><input type=\"text\" name=\"email\" value=\"$email\" size=40></td></tr>
                <tr><td>Cell Phone:</td><td><input type=\"text\" name=\"cell_phone\" value=\"$cell_phone\" size=40></td></tr>
                <tr><td>Home Phone:</td><td><input type=\"text\" name=\"home_phone\" value=\"$home_phone\" size=40></td></tr>
                <tr><td></td><td><input type=\"button\" value=\"Save\" class=\"button1\" onclick=\"admin_update_candidate_contact(this.form)\"></td></tr>
                </table>
                </form>
                </div>
0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39955788
Thanks Chris. That's prob what is closing my tag. I will re-work the HTML in a few.
0
 
LVL 7

Author Closing Comment

by:Robert Saylor
ID: 39956465
Thanks it is working now! It was bad HTML closing the form tag. I will remember that for next time.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question