I have a script that reloads a form without refreshing the page. Everything seems to be work fine except when the java script hits the if statement, for some reason. The if statement if(msg == ‘Saved’) conditions seems to never met.
as you can see from the code below i set a couple of alerts and at stage2 alert and at stage 4 alert everything works. event the the variable returned (msg) is confirmed to have the correct value.
any ideas as to whats causing the if statement to by pass?
hello pullo
i copy / pasted the line of code and nothing happend…
my js file is a external file and not sure if that has anything to do wtih you line of code.
thanks for the reply back… after pullo post i looked at the tutorial in the post and i have screen shot maybe you can look at to help me with this issue…
next to the saved theres a return key… is that whats causing the problem…
see screen shot
ok, still not resolved by getting close.
i think it has somehting to do with this line data: $(‘#emailForm1’).serialize(),
now, how do i handle serialize… i think the return value is a object and when i compare object and ‘saved’ its not working.
any ideas how to fix this?
hi Mittineague
originally i had another if statement and if it met “not saved” do something… but i took that out from the javascript to make the debugging easy…
This is actually not true in the case of jQuery. Using the $.ajax() method, you can set the dataType attribute to specify the type of data that you’re expecting back from the server. If none is specified (as here), jQuery will try to infer it based on the MIME type of the response and it is quite conceivable that it will default to a plain text string.
As for the OP’s original problem, something else is at play. I just made a simple demo: