So I have a big goal I'm trying to accomplish but since I haven't gotten an answer yet I think its too broad and I realize I may be missing some Ajax/jQuery fundamentals so I want to start a fresh post here to get any help I can.

I have an HTML button that calls this inline JS:

<script type="text/javascript" >
	$(function() {
		//var currID = <?php echo ($currID); ?>;
		$(".update_button").click(function() {
			
			$.post("liveNews.php", {'currID[]': ["2806","2143","2139"]},
			function(data) {
			   alert("Data Loaded: " + data);
			 });
		});
	});
</script>

At the moment I get an alert button, but only with the "Data Loaded: " text, the data is blank. As a new person to ajax what can I put in my php file to get data that I can use? Meaning can I make it give me all the html I need to populate for a new post, or should I only have it return portions of data that I then have to format to display the way I want?

Also at the moment is this the right way to send to the liveNews.php so that it can actually receive the array to use in filtering out which post to not query?

Thank you in advance for any guidance I can get with this.

Member Avatar for stbuchok

Look into webservices and returning JSON.

Is there something specific you're referencing. This seems like a very broad search and I'm not sure how JSON fits in with Ajax/jQuery yet so this could lead me chasing more answers and I'm not sure I understand why. Can this not be done with Ajax/jQuery alone?

Member Avatar for stbuchok

Webservices are the proper way to get information from a web site through AJAX (you can use other ways, but I've always found this way to be much clearer and extensible). JSON is a data format that the webservice can return that is meant to be used with JavaScript (similar in a way to returning XML but has a structure that is almost identical to create anonymous objects).

The only other thing you can look at is, does the page you are pointing to return any data when you navigate to it?

make sure the dataType is set correctly for the $.post request (you could try using the underlying $.ajax version of the function). If using plain text responses etc, you may have to use eval(data) etc depending on the data that is being returned/expected.

For effective communication and information transfers, JSON is recommended as the return data format (MIME: application/json) as the data objects can be interpreted directly within the javascript code.

Also, make sure to include return false at the end of the click handler to prevent the browser's default click action triggering after the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.