Cross Domain Error with WPML- No 'Access-Control-Allow-Origin' header is present

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Cross Domain Error with WPML- No 'Access-Control-Allow-Origin' header is present

This topic contains 7 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 7 years, 6 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #10316
    Ramiro Ramirez
    Ramiro Ramirez
    Participant

    Hi there,

    I’m using Ajax Search Pro with WPML.

    The problema is that I’m using different domains to serve different languages. So when the user uses the search bar in one of the secondary language domains the search gets blocked because of the cross domains restrictions.

    I see the following error getting generated when I start a search.
    —————————————————-
    XMLHttpRequest cannot load http://www.vinozarchivu.cz/wp-content/plugins/ajax-search-pro/ajax_search.php. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://www.winefromthearchive.com’ is therefore not allowed access.
    —————————————————

    Is there a way to add something like this to the HTTP request header?
    response.addHeader(“Access-Control-Allow-Origin”, “http://www.vinozarchivu.cz”);

    Or do you have any idea on how to prevent the cross domain restrictions.

    Thanks for your help.

    #10318
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    I’m not sure if this is going to work at all, even if somehow the cross domain restriction is fixed, but it’s worth a try of course.

    The access must be granted on the target server. In this case you need to edit the wp-content/plugins/ajax-search-pro/ajax_search.php file and add this line after line 20:

    Don’t forget to change the yourdomain.com to the other domain (the “www.” part might be needed as well, I’m not sure).

    If that doesn’t work, then there is a possible .htaccess solution as well:

    
    <ifModule mod_headers.c>
        Header set Access-Control-Allow-Origin: *
    </ifModule>
    

    However I don’t know how dangerous this is, as it allows cross domain requests from everywhere, so please be careful.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10324
    Ramiro Ramirez
    Ramiro Ramirez
    Participant

    Thank you so much! I’ve implemented the header in the .htaccess so I can leave the plugin code intact. I managed to declare the header for a specific domain and it seams to be working:

    &lt;ifModule mod_headers.c&gt;
        Header set Access-Control-Allow-Origin: http://www.winefromthearchive.com
    &lt;/ifModule&gt;

    I just noticed that the search bar is working now but, it’s displaying the results for the main language (Cz) only.

    I’ve checked and the WPML compatibility is set to ON.

    Any ideas on what may be causing this? Should I create a different ticket for this issue?

    Thanks again for your help!
    R.

    #10326
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I think that’s because of the cross domain request, I’m not sure if that’s possible to solve. I suspected an issue with it, but I can check it if you want to, but I cannot promise it will function correctly.

    You can post details in this thread and mark it as private reply, or edit the initial post to enter the details, or upload a txt file with private details – or you can open another one if you want to. (temporary FTP and admin details)
    I would like to check and debug the code to see if there is anything I can do to get the correct language.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10328
    Ramiro Ramirez
    Ramiro Ramirez
    Participant
    You cannot access this content.
    #10337
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    The problem was that the custom ajax handler was enabled on the Compatibility Settings panel.

    Because of that the WPML was not yet fully loaded when the search process was already finished – returning the incorrect permalink for the products.

    The custom ajax handler feature is a great thing, but there is no guarantee it will work in every specific case, such as yours unfortunately. However the results should be pointing to the correct URL now.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10338
    Ramiro Ramirez
    Ramiro Ramirez
    Participant

    Wah, everything is working properly now!

    You know, I’ve been developing for WordPress for almost 5 years now. And this hast to be the best support I ever gotten for a plugin so complex as yours.

    Thank you so much for your kind attention.

    Hope you have a great week,
    R.

    #10340
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You are very welcome, I’m happy I was able to help you, and thank you very much for your kind words! 🙂

    If you don’t mind, I will close this topic and mark it as resolved for now, feel free to open another one if you have other issues.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Cross Domain Error with WPML- No 'Access-Control-Allow-Origin' header is present’ is closed to new replies.