Jump to content

javascript and php variables??


shadiadiph

Recommended Posts

I have been building an AJAX form my javascript knowledge is terrible but I am having a horribble time with javascript variables I assign the response var a = xmlHttp.responseText etc result which it gets fine why if i get a response from an xml node the javascript variable can compare if (var a =="error") { do this } else { do that} but with the .responseText reply will not recognise it and jump straight to the else I have tried returning a number as an error false as an error javascript just won't seem to read a returned variable properly I even tried .length==0 no joy??? Any tips? I'm beginning to think javascript and php were not supposed to coexist :(

Link to comment
Share on other sites

By the way I read 4 different alphabets and speak 6 languages.

 

Isn't that impressive. Let me give you a cookie.

 

Anyways, my point was that if you don't write your problem in a manner that's easy to understand, you aren't likely to get help for it.

Link to comment
Share on other sites

Ok I have a form it is sending country,state,city,postal step by step with AJAX to a php page it either returns "error" if the next set of data is not found and does not display the div.

 

Problem is when i use

 

var result = xmlHttp.responseText;

if (result=="error')
{
//hide div
}
else
{
// display div
}

 

It doesn't recognise the word error but displays error as the else result

 

I have tried

 

var resultlen = result.length;

 

it keeps returning 8 if I don't return anything the length is 3 my question is why can't javascript not recognise the string with the value of error?  When I did this a different way using <xml> calling the node values it recognised the text string if (result=="error") etc it understood that but why not with xmlHttp.responseText; and how to deal with this?

 

 

Link to comment
Share on other sites

right now here is my code the alert returns nostates when i select a country that has no states and when it has it returns the correct value but everytime it only executes the else statement regardless??

 

document.getElementById("tempresult").value=xmlHttp.responseText;

var stateval;
var stateval = document.getElementById("tempresult").value;

alert('State Value' +stateval);

if (stateval == "nostates")
{
document.getElementById('staterow').style.visibility='hidden';
document.getElementById('cityrow').style.visibility='hidden';
document.getElementById('postalrow').style.visibility='hidden';
getcitybycc();  
}
else
{
document.getElementById('staterow').style.visibility='visible';
document.getElementById('stateinput').innerHTML=xmlHttp.responseText;
document.getElementById('cityrow').style.visibility='hidden';
document.getElementById('postalrow').style.visibility='hidden';
}

 

I also get the same if i use

 

document.getElementById('tempresult').innerHTML=xmlHttp.responseText;

 

my php page

 

if ($states==false)
{
$result = 'nostates';
$result = trim($result);
return $result;
exit;
}

 

 

i tried it with trim without trim still the same result

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.