I am running this on my local:

<script>
            $(document).ready(function() {
                $("#validateButton").click(function() {
                    var forename = $("#Name").val();
                    var surname = $("#Surname").val();
                    var dob = $("#DOB").val();
                    var flatNumber = $("#FlatNumber").val();
                    var houseName = $("#HouseName").val();
                    var houseNumber = $("#HouseNumber").val();
                    var street = $("#Street").val();
                    var townCity = $("#TownCity").val();
                    var county = $("#County").val();
                    var postcode = $("#Postcode").val();
                    var sortcode = $("#AccountSortCode").val();
                    var accountNumber = $("#AccountNumber").val();

                    var parameters = {forename:forename, surname:surname, dob:dob, flatNumber:flatNumber, houseName:houseName, houseNumber:houseNumber, street:street, townCity:townCity, county:county, postcode:postcode, sortcode:sortcode, accountNumber:accountNumber};

                    $.post("Validate.php", parameters, function(result) { 
                        $.each(result, function(key, value) {
                            alert(key);
                            if (key == 'AuthenticationDecision') { $("#validationResult").html(value) };
                        });
                    });
                });
            });
        </script>

which brings in this array from the php script:

{"AuthenticationDecision":"Not Authenticated","NameScore":0,"AddressScore":0}

and runs as expected.

When I try to run the same thing on the host server, alert(key) just returns 0,1,2,3,... until I stop it.

If I run the validate.php script on its own on the host it outputs the data just fine.

If I don't post the data and just hardcode it in the validate.php, the result is also wrong, once I click the id.

I assume the issue is when the result is actually returned if it is returned at all.

Does anyone know of any reason why I might be getting this behaviour?

Thanks for any help offered.

First up, you would probably save yourself some work by using

var parameters = $("yourformid").serialize();

Second:
Your host server php is behaving differently to your local dev so you would probably want to categorise this issue under php rather than js/dhtml.
Start debugging by making your validate button submit the form normally so you can see the actual response returned by the php - or

$.post("Validate.php", parameters, function(result){
    $("#validationResult").html(result);
});

This way you can compare what Validate.php renders on both server and dev and cross reference it with what is in both databases. That way you can tell if the php is behaving differently or the results are due to the host server database having more or different data.

Thanks vsmash. I'll give that a go and see what happens.

The data isn't coming from a database though. It is hardcoded in the php script currently. It is the same script running on local and host.

Member Avatar for iamthwee

Assuming you are using the same script on localhost and host server and all other things being equal- script on localhost works so you say.

Vsmash is spot on. You hosting config is different maybe a different version of PHP which is one such cause, htaccess files could be another.

Perhaps you didn't copy the script over properly... Or someone changed it accidentally.

But when I run the php script on its own I get the correct output, to the screen (i.e, the json_encoded array). It's only when passing via the JQuery that it goes loopy :S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.