I am trying to get response from a php page using jQuery Ajax. Everything works fine until I tried to explode an array and combined it elements to get a time 09:00.
Console says, Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: 00 and nothing displayed.
My code is,
$starttimeArr= explode(",",$comma_separated_starttime);// explodes 09,00,00
$endtimeArr= explode(",",$comma_separated_endtime);// explodes 17,00,00
echo $starttime= $starttimeArr[0].":".$starttimeArr[1];// combine to get 09:00. The line pop up the error
$endtime= $endtimeArr[0].":".$endtimeArr[1];// combines to get 17:00
How did I overcome this error? Any help will be appreciated.
My Ajax code is
jQuery("#_dob").change(function() {
jQuery.ajax({
url: "<?php echo $this->getUrl('deliverybydatepro/index/index') ?>",
data: "checkIn="+jQuery(this).val()+"&type=calendar",
type: "GET",
dataType: "html",
success: function(data) {
var $response=jQuery(data);
jQuery("#div1").html(data);
}
});
});
The response page has a dropdown having an option "09:00". jQuery-1.8.0 triggers an error on it.
Okay. Having seen the edited question with the JS code, the problem is clear:
This line is the cause of the error.
The
datavariable is the response string from the AJAX request. This contains the string “09:00”, as expected.This means that your code is equivalent of calling
jQuery('09:00').jQuery will try to interpret that as a CSS selector. It will see the
09and try to find an element with that name. It won’t find one of course, but it won’t complain about that. However it will then see the:00and assume that’s a pseudo-selector (like:beforeor:first-child, etc). Of course:00is not a valid pseudo-selector, and jQuery will complain about that. So that’s where the error is coming from.So what to do about it? Well the answer is quite simple, really.
You’re using this line to set a variable called
$response, but then you’re never using that variable; you’re continuing to use thedatavariable. So really the whole of the line that is throwing the error is completely unnecessary. You may need a line like that if your PHP is outputting JSON or XML data, but not if it’s a plain string.So the solution is to remove that line entirely.
Hope that helps.
Just as an aside, to help you out for next time, it would have been fairly easy to find out which line of JS code was causing the problem by using the debugger in the browser. Just open the Dev Tools or Firebug, and run the code, and it would stop and show you exactly where the error is. A little bit of further work with the debugger looking at variables, and it would probably have become clear what the problem was.