Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-11-2012, 07:36 PM   PM User | #1
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,431
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
$.ajax not working

I have a script that was working with a jquery-1.4.2.min.js

now i got rid of that and i have jquery.js on the page

$.ajax({
url: urltoajax,
cache: false,
success: function (html) {
$("#mydiv").html(html);
}
});

what is missing? my problem is the jquery-1.4.2.min.js conflicted with something else on the page that needed the jquery.js

plese advise
esthera is offline   Reply With Quote
Old 07-12-2012, 03:37 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,396
Thanks: 18
Thanked 352 Times in 351 Posts
sunfighter is on a distinguished road
Quote:
my problem is the jquery-1.4.2.min.js conflicted with something else on the page that needed the jquery.js
I really doubt this. The newest jq is ver 1.7.2.

My thoughts on the code is, don't use html to mean the results that the called file sends back. It does work, but html has another meaning so why confuse things. Use
Code:
success: function (result) {
Your file name needs to be in quotes. Is this the real file name
Code:
urltoajax
? Or a representation of it?

Code that works:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="./lib/jquery-1.7.2.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {
	$("button").click(function(){

		$.ajax({
			url: "ajax.php",
			cache: false,
			success: function (result) {
				$("#mydiv").html(result);
			}
		});

	});
});
</script>

</head>
<body>
<div id="mydiv">Ajax will write here</div>
<button>Do AjAx Stuff</button>
</body>
</html>
My ajax.php file is this:
PHP Code:
<?php
echo 'made it';
?>
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:43 PM.


Advertisement
Log in to turn off these ads.