Category Archives: ajax

Prestashop modules/path is not found

guys today i install modules for version 1.7.X on my prestashop store, my prestashop version is correct 1.7.X but if i try to open modules in browser developer console i found this error : http://motokayak.eu/modules/econt/ajax.php?ajax_function=get_cities_by_name&q=dsad&limit=10&timestamp=1526125310888 404 (Not Found) My file is in folder but prestashop not founded and if i try to open this link http://motokayak.eu/modules/econt/ajax.php in my browser site return 404 not found why ?

Picture 1 enter image description here

Picture 2 enter image description here

Picture 3 enter image description here

onchange get current value with radioChoice

Im trying to get the selected value from a radio form with radioChoice onChange but can't really seem to find the solution. The onEvent function gets called, but from here I'm not really sure how to get the value.

Code:

    RadioChoice<String> radioChoice = new RadioChoice<String>("radio", new PropertyModel<String>(this, "selected"),this.radioChoiceList);
    radioChoice.add(new AjaxFormComponentUpdatingBehavior("change")
    {
        @Override
        protected void onUpdate(AjaxRequestTarget target)
        {
            System.out.println("ajax here!");
        }
    });
    Form<?> form = new Form<Void>("form");

    add(form);
    form.add(radioChoice);

Need a rewrite for a semantic API endpoint

I am using ExpressionEngine and am writing an addon in which I need the endpoints to be more semantic https://www.example.com/api/method rather than the typical https://www.example.com/?ACT=24.

My primary issue is that the methosd receive a POST. I know redirects drop POST data and I can't use a GET. The site is on a shared server so I don't have much control over the server settings if any at all.

I have tried various rewrites in the .htaccess file. I have also tried using a nginx.conf file since it is running on apache with nginx too.

Is this something that is possible or am I just out of luck here?

Here is the last attempt. I was hoping a simple rewrite would work, but it acts as thought the .htaccess file doesn't even get hit when I do this and check it. I have tried using 307, 308, but both failed.

RewriteEngine On
RewriteBase /

# APIs
RewriteCond %{REQUEST_URI} ^/api/add_products$ [NC]
RewriteRule ^.*$ /index.php?ACT=150 [NE,NC,L]

# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/(.*) /$1$2 [R=302,NE,L]

# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

preflight OPTIONS check gives 403 with Access-Control-Allow-Origin ”*”

I have a single page app served on one subdomain and an api on another. I get a 403 Forbidden on the pre-flight check for an XHR POST to the api.

Debugging it in curl shows:

 curl  -H "Host: backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com" \
 -H "Origin: http://frontend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: content-type" \
-X OPTIONS --verbose http://backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com/api/users
*   Trying 54.153.79.158...
* TCP_NODELAY set
* Connected to backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com (54.153.79.158) port 80 (#0)
> OPTIONS /api/users HTTP/1.1
> Host: backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com
> User-Agent: curl/7.54.0
> Accept: */*
> Origin: http://frontend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com
> Access-Control-Request-Method: POST
> Access-Control-Request-Headers: content-type
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 403 Forbidden
< Date: Fri, 04 May 2018 21:16:52 GMT
< Server: Apache/2.4.27 (Red Hat) OpenSSL/1.0.1e-fips
< Cache-Control: no-cache, private
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: accept, access-control-allow-origin, content-type
< Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
< Content-Length: 18
< Content-Type: text/html; charset=UTF-8
< Set-Cookie: 45fe47f0bb613513b8e98d0599b628f9=dd4b5c95b51d6168419458748b392421; path=/; HttpOnly
* HTTP/1.0 connection set to keep alive!
< Connection: keep-alive
< 
* Connection #0 to host backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com left intact
Origin not allowed

Yet the Access-Control-Allow-Origin: * in the response suggests that it should allow the Origin: http://frontend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com named the request.

If I drop the Origin header from the request I get a 200.

I tried explicitly setting the Access-Control-Allow-Origin on the server to match match the Origin of the request but that also gets back a 403:

 curl  -H "Host: backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com" \
 -H "Origin: http://frontend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: content-type" \
-X OPTIONS --verbose http://backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com/api/users
*   Trying 54.153.79.158...
* TCP_NODELAY set
* Connected to backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com (54.153.79.158) port 80 (#0)
> OPTIONS /api/users HTTP/1.1
> Host: backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com
> User-Agent: curl/7.54.0
> Accept: */*
> Origin: http://frontend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com
> Access-Control-Request-Method: POST
> Access-Control-Request-Headers: content-type
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 403 Forbidden
< Date: Fri, 04 May 2018 21:32:52 GMT
< Server: Apache/2.4.27 (Red Hat) OpenSSL/1.0.1e-fips
< Cache-Control: no-cache, private
< Access-Control-Allow-Origin: http://frontend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com
< Access-Control-Allow-Headers: accept, access-control-allow-origin, content-type
< Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
< Content-Length: 18
< Content-Type: text/html; charset=UTF-8
< Set-Cookie: 45fe47f0bb613513b8e98d0599b628f9=a913ecc9ded73c3ac76fbb38d93e15a7; path=/; HttpOnly
* HTTP/1.0 connection set to keep alive!
< Connection: keep-alive
< 
* Connection #0 to host backend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com left intact
Origin not allowed

On the server the .htaccess has the following configuration:

<IfModule mod_headers.c>
    Header add Access-Control-Allow-Origin "http://frontend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com"
    Header add Access-Control-Allow-Headers "accept, access-control-allow-origin, content-type"
    Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
</IfModule>

Setting the Access-Control-Allow-Origin to "*" doesn't fix the issue.

Why is the response 403 forbidden when the origin seems to be allowed and how might I fix it?

Thanks!

POST params stripped .htaccess basic auth

I'm basically trying to send an AJAX-Add-to-Cart-POST-Request by WooCommerce WordPress Plugin. The Plugin does so by sending form-data to a URL that already contains a GET param:

jQuery.post('/?wc-ajax=add_to_cart', { product_id: '123', quantity: 1 }, function(response) {...});

This works fine locally, but on the staging server, which is secured by basic htaccess auth:

AuthName "Staging"
AuthUserFile /path/to/.htpasswd
AuthType Basic
Require valid-user

the POST params are completely stripped from the request, means when I remove the above or "whitelist" my IP like so:

Order allow,deny
Allow from 1.2.3.4
Satisfy Any

everything works fine.

Is there something I'm missing? I could not find any documentation why this behaves the way it does.

The site runs on an apache 2.4 server with php 7.1.17, OS is Debian 8.10.

.htaccess special rule exception for ajax?

So having very little experience with Regex as well as minor beef with .htaccess I need to ask this:

I want to use AJAX on my site, but my mod rewrite configuration prevents me from doing this properly, as I redirected all urls to my index.php and set the url $_GET variable, this is my current setup:

RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

Now I want this rule to not fire if the query contains "&ajax&" as a string, at least I always append "&ajax&time=..." to the ajax path that I want to load.

So I thought it would be easiest to check if I can match "ajax" and use the [S]kip or [L]ast Flag to prevent the other rule to fire, but haven't been able to achieve it yet, any help? With explanations or pointers toward some?

Also, it would be neat if this doesn't require absolute urls or anything, as I want it to work in both development (localhost) and live (actual domain) environment without changing the .htaccess file accordingly.

SO

  • I want the url example.com/profile
  • to be redirected to example.com/index.php?url=profile

AND

  • I want the url example.com/src/file.php?stuff=something&ajax&time=1234
  • to stay example.com/src/file.php?stuff=something&ajax&time=1234

BUT

  • I want the url example.com/ajax
  • to also be redirected to example.com/index.php?url=ajax (just in case)

Any help is greatly appreciated, thanks!

Using xml http request, not able to upload large files to server it is limited to 120mb

On .htaccess the memory_limit, post_max_size, max_execution_time, max_input_time, upload_max_filesize and LimitRequestBody set as 0 all these are changed as required and that are reflected also, but the upload is limited to 120mb and <120mb it works well.

  • SSL certified web server is using, is need to add more in .htaccess like SSLRenegBufferSize....

If i try to upload more than 120mb like six 25mb files at a time only 4 are uploaded to server and no response from http request url.

Working on it from last few days but no luck. Thanks in advance for the help.

The following script will run on click on submit button of the code in html

<script>
            var loadingStatus, percentStatus;
            function sendFile(e) {
            e.preventDefault();
var url = "filemove_email.php";
            var formD = new FormData(document.getElementById("form"));

            var xhr = new XMLHttpRequest();

                xhr.open("POST", url, true);
            var loadingStatus = document.getElementById('popupModal');
            var percentStatus = document.getElementById('percentage_completed');
                xhr.upload.onprogress = function (e) {
                    var maxi = e.total;
                    var calcc = e.loaded * 100 / e.total;
                    percentStatus.innerHTML = calcc.toFixed() + '%';
                    loadingStatus.style.display = "block";
                };
                xhr.onloadend = function () {
                    loadingStatus.style.display = "none";
                };
                xhr.responseType = 'text';
                xhr.onreadystatechange = function() {
                    if(xhr.readyState == 4 && xhr.status == 200)
                    {
                        document.getElementById("response").innerHTML = xhr.responseText;
                        if(xhr.responseText == "file uploaded successfully") {
                   alert('succesfully uploaded'); 
                   loadingStatus.style.display = "none";
                        }
                    }
                }
                xhr.send(formD);
}
                </script>

filemove_email file

$rand_num = rand(1000, 99999);
    $fileName1 = $_FILES["upload_file1"]["name"]; 
    $fileName2 = $_FILES["upload_file2"]["name"];
$fileName3 = $_FILES["upload_file3"]["name"]; 
    $fileName4 = $_FILES["upload_file4"]["name"];
    $fileName5 = $_FILES["upload_file5"]["name"]; 
    $fileName6 = $_FILES["upload_file6"]["name"];
    $fileName7 = $_FILES["upload_file7"]["name"]; 
    $fileName8 = $_FILES["upload_file8"]["name"]; 
$endfileName1 = $rand_num .".". $_FILES["upload_file1"]["name"]; 
    $endfileName2 = $rand_num .".". $_FILES["upload_file2"]["name"];
    $endfileName3 = $rand_num .".". $_FILES["upload_file3"]["name"]; 
    $endfileName4 = $rand_num .".". $_FILES["upload_file4"]["name"];
    $endfileName5 = $rand_num .".". $_FILES["upload_file5"]["name"]; 
    $endfileName6 = $rand_num .".". $_FILES["upload_file6"]["name"];
    $endfileName7 = $rand_num .".". $_FILES["upload_file7"]["name"]; 
    $endfileName8 = $rand_num .".". $_FILES["upload_file8"]["name"]; 

    $fileTmpLoc1 = $_FILES["upload_file1"]["tmp_name"]; 
    $fileTmpLoc2 = $_FILES["upload_file2"]["tmp_name"];
    $fileTmpLoc3 = $_FILES["upload_file3"]["tmp_name"]; 
    $fileTmpLoc4 = $_FILES["upload_file4"]["tmp_name"];
    $fileTmpLoc5 = $_FILES["upload_file5"]["tmp_name"]; 
    $fileTmpLoc6 = $_FILES["upload_file6"]["tmp_name"];
    $fileTmpLoc7 = $_FILES["upload_file7"]["tmp_name"]; 
    $fileTmpLoc8 = $_FILES["upload_file8"]["tmp_name"]; 

$fileType1 = $_FILES["upload_file1"]["type"]; 
    $fileType2 = $_FILES["upload_file2"]["type"];
    $fileType3 = $_FILES["upload_file3"]["type"]; 
    $fileType4 = $_FILES["upload_file4"]["type"];
    $fileType5 = $_FILES["upload_file5"]["type"]; 
    $fileType6 = $_FILES["upload_file6"]["type"];
    $fileType7 = $_FILES["upload_file7"]["type"]; 
    $fileType8 = $_FILES["upload_file8"]["type"];


$fileSize1 = $_FILES["upload_file1"]["size"]; 
    $fileSize2 = $_FILES["upload_file2"]["size"];
    $fileSize3 = $_FILES["upload_file3"]["size"]; 
    $fileSize4 = $_FILES["upload_file4"]["size"];
    $fileSize5 = $_FILES["upload_file5"]["size"]; 
    $fileSize6 = $_FILES["upload_file6"]["size"];
    $fileSize7 = $_FILES["upload_file7"]["size"]; 
    $fileSize8 = $_FILES["upload_file8"]["size"];


if(isset($_FILES["upload_file1"])) {
        move_uploaded_file($fileTmpLoc1, "uploads/$rand_num.$fileName1");
    } 
    if(isset($_FILES["upload_file2"]))
        move_uploaded_file($fileTmpLoc2, "uploads/$rand_num.$fileName2");

    if(isset($_FILES["upload_file3"]))
        move_uploaded_file($fileTmpLoc3, "uploads/$rand_num.$fileName3");   

    if(isset($_FILES["upload_file4"]))
        move_uploaded_file($fileTmpLoc4, "uploads/$rand_num.$fileName4");

    if(isset($_FILES["upload_file5"]))
        move_uploaded_file($fileTmpLoc5, "uploads/$rand_num.$fileName5");

    if(isset($_FILES["upload_file6"]))
        move_uploaded_file($fileTmpLoc6, "upload/$rand_num.$fileName6");

    if(isset($_FILES["upload_file7"]))
        move_uploaded_file($fileTmpLoc7, "uploads/$rand_num.$fileName7");

    if(isset($_FILES["upload_file8"]))
        move_uploaded_file($fileTmpLoc8, "uploads/$rand_num.$fileName8");


    //mail sending code



if(mail ($to,$subject,$body,$headers) && mail ($to2,$subject2,$body2,$headers2))
    {
    echo "file uploaded successfully";
    }
    else
    {
    echo "Upload error!";
    }
    exit;
}

js not submitting form by setting dynamic action

working on wordpress, having page template, there is ajax call which check the voucher code and set the action dynamically, and submit form to redeem voucher,

$.ajax({ 
                    type: 'POST', 
                    url: ajaxurl, 
                    data: action_data, 
                    dataType: 'json',
                    success: function (response) { 
                        $(".loading").hide();
                        btn.prop('disabled',false);
                        btn.removeAttr("disabled");

                        if(response.status==1){
                            $(".response").html(response.message);
                            $(".response").show().delay(2000).hide(0);
                            var redirectUrl = "<?php echo get_bloginfo('url'); ?>/"+response.redirect_link+"/";
                            alert(redirectUrl);

                            form.attr('action',redirectUrl);


                        }else{
                            $("#voucher_code").addClass("error-fld");
                            $(".response").html(response.message);
                            $(".response").show().delay(3000).hide(0);
                            //return true;
                        }
                    }
                });

Also i have rule in my htaccess that all urls should append "/" in the end otherwise redirect it to referrer URL,

RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteCond %{REQUEST_URI} !wp-json/contact-form-7/v1/contact-forms/1404/feedback
RewriteCond %{REQUEST_URI} !wp-json/contact-form-7/v1/contact-forms/1740/feedback
RewriteCond %{REQUEST_URI} !wp-json/contact-form-7/v1/contact-forms
RewriteRule ^(.*)$ https://example.com/$1/ [L,R=301]

Problem if i hardcode action in tag it works fine, but through setting jquery doesn't submit. also i have check the response in ajax also alerted redirect link have "/" also in the end, and in network tab, however it redirect to dynamic url through jquery, but show 302 error in network tab, sorry for my bad english , open to answer any question, any idea guys?

Cross domain AJAX 403 Error

I am getting a 403 Forbidden status code when making an AJAX GET call from another domain. It works if I put the files on the same domain but I would like to enable cross domains. My code is:

 $.ajax({
    url: "https://example.com/api/details/status/1",
    type: "GET",
    headers: {
        'authkey': 'password'
        },
        dataType: "json",
        contentType: 'application/json',
        async: true,
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success: function (data, textStatus, xhr) {
     console.log(data);
   },
   error: function (xhr, textStatus, errorThrown) {
     console.log(errorThrown);
   }

});
}

I have this in example.com htaccess:

Header set Access-Control-Allow-Origin "http://exampleajax.com"
Header set Access-Control-Allow-Credentials true
Header set Access-Control-Allow-Headers "*"
Header set Access-Control-Allow-Method "*"

The console says this:

GENERAL

Request URL: https://example.com/api/details/status/1
Request Method:OPTIONS
Status Code:403 Forbidden
Remote Address:193.242.154.190:443
Referrer Policy:no-referrer-when-downgrade

RESPONSE HEADERS

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:*
Access-Control-Allow-Method:*
Access-Control-Allow-Origin:http://exampleajax.com
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:keep-alive, Keep-Alive
Content-Type:application/json; charset=utf-8
Date:Sat, 29 Jul 2017 09:13:10 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache/2.4.27 (cPanel) OpenSSL/1.0.2k mod_bwlimited/1.4
Set-Cookie:currency=EUR; expires=Mon, 28-Aug-2017 09:13:10 GMT; path=/; domain=www.example.com
Set-Cookie:language=sl-SI; expires=Mon, 28-Aug-2017 09:13:10 GMT; path=/; domain=www.example.com
Set-Cookie:PHPSESSID=03opu95ddo4fon0udk7ho4rvl5; path=/; HttpOnly
Set-Cookie:default=eba7a5c318db689b3b11473819; path=/; httponly
Transfer-Encoding:chunked
Vary:User-Agent

REQUEST HEADERS

Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-GB,en;q=0.8,en-US;q=0.6,sl;q=0.4
Access-Control-Request-Headers:content-type,x-oc-restadmin-id
Access-Control-Request-Method:GET
Connection:keep-alive
Host:example.com
Origin:http://examplelanding.com
Referer:http://examplelanding.com
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36

Anybody got an idea what am I missing here? Maybe a thing in htaccess?

Thanks!

Cannot allocate memory, couldn’t create child process : Do I need to queue the PHP-image requests?

I'm having trouble displaying my images on my web-pages. The images are being fetched by a php-script.

The images on the pages have the source of a .php-file which fetches an image based on a filereference. http://www.website.com/getImage.php?file=filename

And then the php-file has the content of:

if (file_exists($fileDir . $file)){
$contents = file_get_contents($fileDir . $file);
echo $contents;}

Of course the filename and directory is fetched from a database and used as the variable $file there.

The actual problem is that the servers Virtual memory is capped really easily (fetching 6 images, each sized around 200kb), resulting in HTTP500.

Cpanels error log states (for each HTTP500):

[Sun Jun 25 15:31:00.131534 2017] [:error] [pid 398316:tid 140190395291392] (12)Cannot allocate memory: [client 85.76.42.74:50544] couldn't create child process: /usr/sbin/suphp for /home/username/public_html/getImage.php, referer: http://www.website.com/index.php

This is really an issue as some images don't load at all (there is no specific order in which they decide to appear or not to appear).

I've tried to contact my service-provider but they keep saying "Myes, the server's capacity is topped out.".

This can't be the case as there is hardly any traffic other than myself and a few others on my server. And the requests I send are very small (text-based article and then these images).

But the thing is, am I missing something on the image-fetch? Am I supposed to clean-up some variables or free-up memory for use after each fetch?

I don't use any libraries or anything, I've written everything myself.

I'll be happy to reply to any further questions in order to get this thing going, its really frustrating. :(