ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Custom http POST for search

July 04, 2008 11:23am

Subscribe [2]
  • #1 / Jul 04, 2008 11:23am

    Rutger

    25 posts

    Hi all,

    I’m working on a Ajax-ified version of a searchfield. Now in my case this means that i must do a POST to the site root with the proper attributes and values to get a searchquery to EE.

    In javascript i create an XMLHttpRequest and tried to send the following POST command.

    <a href="http://myeeinstallation.com/?ACT=19&XID=fac52bed0908110e475d3b519997142edbe739a9&RP=search&#47results&NRP=&RES=&status=&search_in=&site_id=1&keywords=tryout&search_in=titles&where=exact&weblog_id&#91&#93=null&cat_id&#91&#93=all&member_name=&date=0&date_order=newer&orderby=date&sort_order=desc">http://myeeinstallation.com/?ACT=19&XID=fac52bed0908110e475d3b519997142edbe739a9&RP=search/results&NRP;=&RES;=&status;=&search;_in=&site_id=1&keywords=tryout&search_in=titles&where=exact&weblog;_id[]=null&cat;_id[]=all&member;_name=&date=0&date_order=newer&orderby=date&sort_order=desc'</a>

    I specified to the XMLHttpRequest object that i’m using the POST method. Unfortunately i get the following response back from the XMLHttpRequest object;

    Invalid GET Data

    Is there anyone that might have some pointers to help me out?

    Thanks in advanced for your effort.

    Rutger

  • #2 / Jul 04, 2008 1:08pm

    Derek Jones

    7561 posts

    If you’re sending POST data, then you don’t need the GET variables you are putting in your URL, Rutger.  Some of the characters you have in there (specifically the brackets), ExpressionEngine views as potentially malicious in the URL and will block the request.  But again, if you are POSTing data, you only need to hit http://example.com/index.php?ACT=19 (or whatever your action ID is).

  • #3 / Jul 04, 2008 3:20pm

    Rutger

    25 posts

    Derek,

    Thank you for your reply. I guess i am a bit further since i now have the

    The search path contains an error. Please contact the system administrator.

    error message.

    There isn’t a solution in doing a GET request to search my EE site is there?

  • #4 / Jul 04, 2008 3:57pm

    Derek Jones

    7561 posts

    I don’t follow, Rutger, you now want to use a GET request for the search?  The error you are receiving is due to there not being an ‘RP’ field in the submitted POST data, the results page path.

  • #5 / Jul 04, 2008 4:13pm

    Rutger

    25 posts

    Derek,

    When i started developing this search feature i was under the assumption that a GET request wasn’t possible to use for EE searches. It would make things easier for me if there is. If there is, i’m not aware of it and someone might enlighten me. That’s why i mentioned it.

    Now when i do use the RP field in my POST http request i get another error message;

    Invalid GET Data

    So i’ll keep trying to see what i’m doing wrong. I am spending hours on this one, i might as well keep going 😊

  • #6 / Jul 04, 2008 4:43pm

    Derek Jones

    7561 posts

    If you’re getting an invalid GET data error, then the problem is with the URL your Ajax method is accessing.  Are you rolling your own request or using a library like JQuery?  The latter would certainly be easier.

    And no, there’s not a direct way to use GET with the Search Module.  It could be done, but you’d have to have an intermediary page request that took the GET and sent its own POST request, so you might as well skip the middle man.

  • #7 / Jul 04, 2008 4:50pm

    Rutger

    25 posts

    You’re right, JQuery would probably be a better choice. But i like to do it ‘head first’. Stupid me 😊
    I’m trying this using the method described here http://www.captain.at/howto-ajax-form-post-request.php

    I don’t get the invalid data error anymore, so i’m getting closer i guess. If i manage to pull this off i think i’ll be writing a guide to do this.

  • #8 / Jul 04, 2008 5:01pm

    Derek Jones

    7561 posts

    I’m sure other users would agree; it would make a great Wiki article, Rutger!

  • #9 / Jul 04, 2008 5:13pm

    Rutger

    25 posts

    Ok, i will write one when i finish this successfully!

    Good news, i’ve managed to complete the issue described above, but now it comes down to browser compatiblity.

    The only issue i’ve got now, that with every character i type, a searchquery is executed resulting in the message;

    You are only allowed to search every 15 seconds.

    Any idea on how to be able to prevent this?

  • #10 / Jul 04, 2008 5:19pm

    Derek Jones

    7561 posts

    Ah, if you’re having it send the query live for each keypress, you’ll need to do one of two things (or both):

    1) put a delay in the js so it only triggers after you’ve stopped entering new keypresses for a few moments
    2) adjust or remove the search throttling in the Membership Preferences

  • #11 / Jul 04, 2008 6:02pm

    Rutger

    25 posts

    Great, thanks for the feedback!

  • #12 / Jul 06, 2008 1:15pm

    Robin Sowell

    13255 posts

    Look forward to seeing the write-up!  Are you still teasing things out- or am I good to go ahead and close the thread?

  • #13 / Jul 06, 2008 1:52pm

    Rutger

    25 posts

    I’m still busy, the only thing i didn’t find that quickly is how to remove the throttling in the admin panel as described. Using JQuery now and so it’s browser compatible. You can close the thread. Thanks.

  • #14 / Jul 08, 2008 12:26pm

    Robin Sowell

    13255 posts

    Good deal- and done!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases