I’m trying to send a simple post via jquery ajax to php and then have php send back a one dimensional array. The problem is that most computers we’ve tested on don’t get an error while others do (usually mac products, but 1 pc) using the same browser and version.
I’ve tried several ways of coding this - including the jquery documented way to no avail. Any help is appreciated.

Ajax code

var value = "uk";

	                type: 'POST',
	                url: 'http://www.xxxxx/x_dropdown.php',
	                cache: false,
	                dataType: 'json',
	                data: 'ajaxSearch=' + value,
	                //contentType: 'application/json',
	                success: function(data) {
			for(var i = 0; i < data.length; i++) {

	                error: function(xhr, textStatus, errorThrown) {
	                    if (textStatus !== null) {
	                        alert("error: " + textStatus);
	                    } else if (errorThrown !== null) {
	                        alert("exception: " + errorThrown.message);
	                    else {
	                        alert ("error");
	                complete: function (xhr, status) {
	                    if (status === 'error' || !xhr.responseText) {
	                        alert('true error');


PHP code

if(isset($_POST[‘ajaxSearch’])) {

$province = $_POST['ajaxSearch'];
$province_array = array();

//make db connection

	while($row = mysql_fetch_assoc($result)) {
		$province_array[$i++] = $row['province'];
    //echo json_encode($province_array);
    print json_encode($province_array);


I found the problem.

It is important to use relative URL’s in AJAX calls otherwise the JS engine might determine that the script is trying to go outside its domain and the request will fail.

Sponsor our Newsletter | Privacy Policy | Terms of Service