Grace Grace - 6 months ago 25
PHP Question

Write a jQuery script that detects a button click and makes an AJax call

What I am trying to write a jQuery script that detects a button click and makes an Ajax call to a json-data-students.php

PHP
script on my server using the .getJSON() function.

I am using Netbeans IDE 8.0.2 I have successfully connected to Mamp and have uploaded my database. I have copied my html and php files to my htdocs folder in Mamp and it still won't call the function which is to display student data. Here is my code, any help as to what I'm doing wrong would be greatly appreciated. I'm pulling my hair out over here!!!

This is the html doc button on my page with the script call at the top of the page.

<div data-role="content">
</div>
<div id="studentList">
<button id="studentButton">Get Student Info</button>


This then is the js file:

$(document).ready(function(){
$.getJSON('http://localhost:8888/php/json-data-students.php',
function(data) {
//Loop through data and extract infromstion for outer listview and inner list view (Part 6 & 7)
$.each(data.students, function(index, student) {
$("#studentList").append('<li><a href="#page2">'+ student.firstName +' '+ student.lastName +'</a><ul><li>Student ID: '+student.studentID+'</li>\n\
<li>Course ID: '+student.courseID+'</li>\n\
<li>Module ID: '+student.moduleNo2+'</li></ul></li>');
});
//Rebuild the list to ensure styling is applied
$("#studentList").listview("refresh");
}); //End of JSON Call
}); //End of document ready function


Error message in Netbeans:

`Failed to load resource: net::ERR_CONNECTION_REFUSED (11:59:47:660 | error, network)
at http://localhost:8888/php/json-data-students.php

Failed to load resource: net::ERR_EMPTY_RESPONSE (11:59:48:567 | error, network)
at http://localhost:8383/favicon.ico


Failed to load resource: net::ERR_EMPTY_RESPONSE (11:59:48:578 | error, network)

at ot.each.contents (chrome- extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/jquery.min.js:2:51 70)
at ot.extend.map (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/jquery.min.js:1:14862)
at ot.each.ot.fn.(anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/jquery.min.js:2:5271)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/components/ActivityMonitor/vie ws/overlay/ActivityMonitorOverlayView.js:1:1894)
at ot.extend.each (chrome- extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/jquery.min.js:1:14059)
at ot.fn.ot.each (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/jquery.min.js:1:11922)
at n.Class.create.bindActivityDetectors (chrome- extension://laankejkbhbdhmipfmgcngdelahlfoji/components/ActivityMonitor/views/overlay/ActivityMonitorOverlayView.js:1:1853)
at i.Class.create.init (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/components/ActivityMonitor/ActivityMonitorController.js:1:255)
at API.Settings.init.n.ready.API.Component.load.onLoaded (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/content.js:1:979)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/ComponentFactory.js:1:943)
at q.execCb (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:12206)
at b.check (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:6455)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:8720)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:710)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:9104)
at each (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:236)
at b.emit (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:9072)
at b.check (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:7000)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:8720)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:710)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:9104)
at each (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:236)
at b.emit (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:9072)
at b.check (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:7000)
at b.enable (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:8970)
at b.init (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:5560)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:7499)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:710)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:9104)
at each (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:236)
at b.emit (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:9072)
at b.check (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:7000)
at b.enable (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:8970)
at b.init (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:5560)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:7729)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/cajon.js:1:710)
at n.finishLoad (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/text.js:1:1576)
at (anonymous function) (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/text.js:1:1797)
at define.node.d.env.d.env.undefined.process.versions.process.versions.node.xhr.d.env.d.env.n.createXhr.n.get.a.onreadystatechange (chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/core/vendor/text.js:1:2866)


Failed to load resource: net::ERR_EMPTY_RESPONSE (11:59:50:461 | error, network)

`

Answer Source

Are sure the file pathhttp://localhost:8888/php/json-data-students.php is correct I mean the port 8888 is it really running, Try one thing open your browser and enter the above url ad hit enter if get your json then url is correct else please check port of on which php is running

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download