1

I don't understand why this is returning the Error function from AJAX. I had it working a few days ago and I don't know how it's failing now. I even super simplified my code to try to fire the success and rebuild the rest.

This is my Jquery:

$("#results").click(function() {
  $.ajax({
    url: "http://www.URL.php",
    type: "POST",
    data: {
      ajaxval: "A"
    },
    dataType: 'text',
    success: function(data) {
      alert(data);
      alert("success");
    },
    error: function() {
      alert("fail");
    }
  });
});

This is my PHP:

<!DOCTYPE html>
<html>

<body>


<?php

$ajaxnum = $_POST['ajaxval'];

echo $ajaxnum;
?>


</body>
</html>

Seems super simple, Please let me know if I'm somehow missing something. Like I said I had a much more complex php returning an html table by way of echoing rows back from a mySQL query result using a loop, etc.

enter image description here

BenG
  • 14,826
  • 5
  • 45
  • 60
Breh
  • 31
  • 8
  • 1
    Can you provide a screenshot of the devtool? – Griffith Nov 04 '15 at 02:47
  • 1
    error reporting and check your console – Funk Forty Niner Nov 04 '15 at 02:52
  • is the request coming from the same domain? - as suggested already, devtools / console - wealth of information for developers can be gained from these simple tools present in all good browsers – Jaromanda X Nov 04 '15 at 02:53
  • added screenshots from the chrome dev tool, click enter img description here – Breh Nov 04 '15 at 02:57
  • no console output in your screenshot – Jaromanda X Nov 04 '15 at 02:57
  • XMLHttpRequest cannot load "URL". No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin "URLoriginal" is therefore not allowed access. – Breh Nov 04 '15 at 02:58
  • sorry just did the devtool, this is the error. I hadn't seen the console error reporting before, pretty new to this kind of programming – Breh Nov 04 '15 at 02:58
  • google that error .... you will find lots of results – charlietfl Nov 04 '15 at 03:01
  • http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource one of many hits. – Funk Forty Niner Nov 04 '15 at 03:02
  • I'm trying to include it in the header, though I'm not 100% sure why I need it since it is coming from the same domain. and it was working a few days ago without this header. but here is the error when I try to put "header('Access-Control-Allow-Origin: *'); " at the top of my php. I get this error Warning: Cannot modify header information - headers already sent by (output started at -URL-/phptestcond.php:38) in /-URL-/phptestcond.php on line 38 – Breh Nov 04 '15 at 03:19
  • Ok I got it, damn that was finnicky. Allowed the origin at the top of the php. Thank you to everyone who herded me towards an answer. I'm trying to rapidly sponge up alot of this stuff, and everyone here is an awesome resource! – Breh Nov 04 '15 at 03:28
  • `www.domain.com` is not the same as `domain.com` - you'll see in your screenshot that the URL requested is `www.buildababe.biz` and the referrer is `buildababe.biz` – Jaromanda X Nov 04 '15 at 03:54

0 Answers0