CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Hybrid View

  1. #1

    Unhappy ? Validation and UNICODE Problems

    Hi, I’m working on a little AJAX app using a PHP script but am having two problems with it:


    (1) My XHTML file won’t validate because of this part:

    Code:
    XMLHttp.send(
    	"action=view"
    	+(form.title.value  == "" ? "" : "&title=" +form.title.value)
    	+(form.artist.value == "" ? "" : "&artist="+form.artist.value)
    	+(form.album.value  == "" ? "" : "&album=" +form.album.value)
    	+(form.year.value   == "" ? "" : "&year="  +form.year.value)
    );
    The validators complain about the ampersands; they say that the entities &title, &artists, &album, and &year are not valid. I tried replacing them with &title, etc. and that does fix the validation, but they no longer register as a parameters in the PHP script.

    Any ideas?


    (2) The PHP script returns some text that is inserted into a DIV on the page from XMLHttp.responseText, but it gets messed up if the returned text has UNICODE characters in it.

    Any ideas?


    Thanks a lot.
    --
    Synetech

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: ? Validation and UNICODE Problems

    You are missing an & behind the "view."

    You really should break up that send command. Try the following.
    Code:
    var theTitle = form.title.value;
    var theArtist = form.artist.value;
    var theAlbum = form.album.value;
    var theYear = form.year.value;
    
    var parameters = "action=view&title=" + theTitle + "&artist=" + theArtist + "&album=" + theAlbum + "&year=" + theYear;
    
    XMLHttp.send(parameters);
    Last edited by PeejAvery; June 20th, 2007 at 03:19 PM.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3

    Re: ? Validation and UNICODE Problems

    “Behind the view”? You didn’t put one behind the view either (and I’m pretty sure it isn’t necessary, possibly even incorrect).


    In any case, I tried your code and it still doesn’t validate; it gives the same errors:
    “Warning: cannot generate system identifier for general entity "title"”
    “Error: general entity "title" not defined and no default entity”
    “Error: reference to entity "title" for which no system identifier could be generated”
    --
    Synetech

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: ? Validation and UNICODE Problems

    No. It is not incorrect. To separate parameters you must use &. When I said behind the view I was talking about...action=view. But I see that I wasn't looking far enough down the code.

    Are you sure you have all the AJAX POST headers set up?

    You should have all the following.
    Code:
    obj.open('POST', url, true);
    obj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    obj.setRequestHeader('Content-length', parameters.length);
    obj.setRequestHeader('Connection', 'close');
    obj.send(parameters);
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5

    Re: ? Validation and UNICODE Problems

    Quote Originally Posted by PeejAvery
    No. It is not incorrect. To separate parameters you must use &. When I said behind the view I was talking about...action=view. But I see that I wasn't looking far enough down the code.
    Oh ok, I thought you meant ?action=view, which I’m fairly sure would be correct because ampersands separate parameters and you can’t put one before the first one.

    Quote Originally Posted by PeejAvery
    Are you sure you have all the AJAX POST headers set up?

    You should have all the following.
    Code:
    obj.open('POST', url, true);
    obj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    obj.setRequestHeader('Content-length', parameters.length);
    obj.setRequestHeader('Connection', 'close');
    obj.send(parameters);
    Pretty sure, I’ve got
    Code:
    XMLHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    
    XMLHttp.setRequestHeader("Charset", "UTF-8");  //this was an attempt to fix problem (2); it didn’t help
    The first line was all that’s listed in the AJAX texts I got it from.

    Problem (1) isn’t an XMLHttpRequest problem anyway, it’s a markup problem. The XHTML validators complain about the presence of an ampersand in the string, but they are necessary to pass multiple parameters.

    Also, any reason you set the open command to synchronous mode?
    --
    Synetech

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: ? Validation and UNICODE Problems

    Quote Originally Posted by Synetech
    Problem (1) isn’t an XMLHttpRequest problem anyway, it’s a markup problem. The XHTML validators complain about the presence of an ampersand in the string, but they are necessary to pass multiple parameters.
    Yes, the markup might be part of the problem, but you said that my example did not work either. That has no markup issues. Can you post the whole page's code?

    Quote Originally Posted by Synetech
    Also, any reason you set the open command to synchronous mode?
    That is just a snippet I had from another piece of code. I used synchronous for control purposes in that script.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured