blingd Posted April 10, 2009 Share Posted April 10, 2009 Ive been having a problem with my php using xml ive gone through it for so long I still cant seem to find the error: Heres my php: <?php $VacancyDetailsRequest = simplexml_load_string($HTTP_RAW_POST_DATA); if (!$VacancyDetailsRequest) die("invalid request XML: if you sent XML did you set the request header to 'Content-Type', 'text/xml' ?"); if (file_exists('vacancies.xml')) { $details = simplexml_load_file('vacancies.xml'); if ($details) { getVacancyDetails($details, $VacancyDetailsRequest->accountNumber); } else { die('vacancies.xml not well formed'); } } else { die('Failed to open vacancies.xml.'); } function getVacancyDetails($details, $accountNumber) { foreach ($details->vacancy as $vacancy) { if ((string)$vacancy->title == (string)$accountNumber) { foreach($vacancy->title as $company) { echo "<p>"; echo htmlentities($company->asXML()); echo "</p>"; } } } } ?> and heres my javascript for it: function getVacancyDetails(accountNumber) { var xml = "<?xml version='1.0' ?>"; xml = xml + "<VacancyDetailsRequest xmlns='http://cs.waikato.ac.nz/~stevej/333/banking/requests'><accountNumber>"; xml = xml + accountNumber; xml = xml + "</accountNumber></VacancyDetailsRequest>"; ajaxRequest("getVacancyDetails.php", "POST", xml, true, showVacancyDetails, true); } function showVacancyDetails(response) { var VacancyListDiv = document.getElementById("VacancyListDiv"); VacancyListDiv.innerHTML = response; } just in case heres my xml <?xml version = "1.0"?> <vacancies xmlns="http://www.cs.waikato.ac.nz/ap65/vacancies/vacancy"> <vacancy> <vid>VAC-2009-03-20-087</vid> <title>Assistant</title> <description>A job for an assistant</description> <company>Fairfax</company> <type>contract</type> <category>Engineering</category> <location>Hamilton</location> <salary>65,000</salary> <eid>EMP-298756</eid> </vacancy> <vacancy> <vid>VAC-2003-04-30-098</vid> <title>Admininstrator</title> <description>Working as the administrator</description> <company>Unisys</company> <type>permanent</type> <category>IT</category> <location>Aucklad</location> <salary>28,000</salary> <eid>EMP-123456</eid> </vacancy> <vacancy> <vid>VAC-2009-05-09-076</vid> <title>Customer Service</title> <description>Be able to communicate with customers</description> <company>Southern Cross</company> <type>contract</type> <category>Engineering</category> <location>Hamilton</location> <salary>15,000</salary> <eid>EMP-654321</eid> </vacancy> <vacancy> <vid>VAC-2007-10-06-051</vid> <title>Maintenance</title> <description>Maintenance of all manufacturing equipment</description> <company>Drake Industrial</company> <type>permanent</type> <category>Engineering</category> <location>Hamilton</location> <salary>40,000</salary> <eid>EMP-789654</eid> </vacancy> </vacancies> I get no output.. can anybody see the error? thankyou Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/ Share on other sites More sharing options...
xtopolis Posted April 10, 2009 Share Posted April 10, 2009 ajaxRequest("getVacancyDetails.php", "POST", xml, true, showVacancyDetails, true); function showVacancyDetails(response) Could the reason be that your ajaxRequest() function , the argument for the callback function is not receiving it's own necessary argument? Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/#findComment-806047 Share on other sites More sharing options...
blingd Posted April 10, 2009 Author Share Posted April 10, 2009 I dnt get you? explain please? Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/#findComment-806111 Share on other sites More sharing options...
xtopolis Posted April 10, 2009 Share Posted April 10, 2009 ajaxRequest is a function that takes arguments. The arguments I can see are: "getVacancyDetails.php", "POST", xml, true, showVacancyDetails, true which means somewhere there is a function defined similar to this: function ajaxRequest(url, method, type, something, callback, something) Your function: showVacancyDetails has it's own argument that it looks for (response) In the main function ajaxRequest, it has showVacancyRequest as a function it calls when the ajax returns data. However, I'm think that because it's calling showVacancyRequest which is equivalent to function showVacancyRequest() that it is not the same as showVancancyRequest(argument). It is hard to tell without seeing the code, but it looks similar to jQuery. Do some alert tests and see at what point the program stops performing as you expect. Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/#findComment-806128 Share on other sites More sharing options...
blingd Posted April 10, 2009 Author Share Posted April 10, 2009 oh yep I understand now yep I put that in a seperate file: ajax.js: function ajaxRequest(url, method, data, asynch, responseHandler, isXML) { var request = new XMLHttpRequest(); request.open(method, url, asynch); if (method == "POST") request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); if (isXML) request.setRequestHeader('Content-Type', 'text/xml'); request.onreadystatechange = function() { alert(request.readyState); if (request.readyState == 4) { alert(request.readyState); if (request.status == 200) { responseHandler(request.responseText); } } }; request.send(data); } Yeh I did a command to output when the file is working but it seems to stop whenever I click on the link. Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/#findComment-806131 Share on other sites More sharing options...
blingd Posted April 12, 2009 Author Share Posted April 12, 2009 Now I understand what you mean xtopolis thanks for that. Ok so now I've added in a response handler in my ajax.js file but now in my job.js file ive added this in but dont know exactly what to write in the var myData = "hello"; anybody know?? function getVacancyDetails(accountNumber) { var myDivId = "vacancyId"; var myData = "hello"; var xml = "<?xml version='1.0' ?>"; xml = xml + "<VacancyDetailsRequest xmlns='http://cs.waikato.ac.nz/~ap65/333/jobs/requests'><accountNumber>"; xml = xml + myData; xml = xml + "</accountNumber></VacancyDetailsRequest>"; ajaxRequest("getVacancyDetails.php", "POST", xml, true, showVacancy, true, myDivId); } function showVacancy(response, VacancyListDiv) { var VacancyListDiv = document.getElementById("VacancyListDiv"); VacancyListDiv.innerHTML = response; } Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/#findComment-807729 Share on other sites More sharing options...
blingd Posted April 13, 2009 Author Share Posted April 13, 2009 Anybody??? Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/#findComment-808377 Share on other sites More sharing options...
blingd Posted April 15, 2009 Author Share Posted April 15, 2009 Ok well I figured what the problem is: It says that "getVacancyList is not defined" Just wondering what this means?? if someone could just explain briefly. Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/#findComment-810294 Share on other sites More sharing options...
xtopolis Posted April 15, 2009 Share Posted April 15, 2009 It means you're calling a function that doesn't exist, most likely due to naming errors or w.e. You've lost me in your previous post when you were talking about "myData". Try to consolidate your errors and break them down into smaller pieces and test them along the way to see where it breaks down in order to narrow your questions/problems down. Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/#findComment-810297 Share on other sites More sharing options...
blingd Posted April 15, 2009 Author Share Posted April 15, 2009 Scrap that before question about myData New Question: I'm getting a error which shows "getVacancyList not defined" so this means its not defined in my javascript right?? well i've added that in like this: vDivList is my reference that defines in in my php file.. so my question is what is wrong with this code? am I missing something. function getVacancyDetails(accountNumber) { var xml = "<?xml version='1.0' ?>"; xml = xml + "<VacancyDetailsRequest xmlns='http://cs.waikato.ac.nz/ap65/vacancies/requests'>"; xml = xml + "<accountNumber>" + accountNumber + "</accountNumber>"; xml = xml + "</VacancyDetailsRequest>"; ajaxRequest("getVacancyDetails.php", "POST", xml, true, showVacancy, true); } function showVacancy(response) { var vListDiv = document.getElementById("vListDiv"); vListDiv.innerHTML = response; } Link to comment https://forums.phpfreaks.com/topic/153416-not-getting-any-result/#findComment-810455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.