DEVHIDE
  • Home (current)
  • About
  • Contact
  • Cookie
  • Home (current)
  • About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy
  • TOS
Login Or Sign up

Something wrong , sending post request using jquery.post()

138 Views Asked by oboualla At 27 September 2020 at 03:05 2025-12-24T01:30:51.006000

I have a file that's called camera.php, here is the source bellow :

camera.php

    <div id="video" style="margin: auto;text-align:center;">
            <video autoplay id="vid"></video>
    </div>
        <button id="start" class="btn" onclick="Start()">Start</button>
        <button id="stop" class="btn" onclick="Stop()">Stop</button>
        <button id="takeshot" class="btn" onclick="TakeShot()">TakeShot</button>
    <canvas id="canvas" width="640" height="480"></canvas>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
        video = document.getElementById('vid');

        function Start() {
            if (navigator.mediaDevices.getUserMedia) {
                navigator.mediaDevices.getUserMedia({video : true}).then((stream) => {
                    video.srcObject = stream;
                });
            }
            else
                console.log('ur navigator does not support getUserMedia !!');
        }

        function Stop() {
            if (video.srcObject)
                video.srcObject = undefined;
        }
        function TakeShot() {
            if (video.srcObject) {
                canvas = document.getElementById('canvas');
                gtc = canvas.getContext('2d');
                gtc.drawImage(video, 0, 0);
                imgData = canvas.toDataURL('image/png');
                //gtc.clearRect(0, 0, canvas.width, canvas.height);
                pb = document.getElementById('pb').value;
                pub(imgData, pb);
            }
            else
                console.log('you need to use Webcam to take a shot');
        }
        function pub(img, pb) {
          // using jquery.post() to send request
           $.post('https://xxxxxx.com/camera/save', {'img' : img, 'pub' : pb, 'stick' : stickSelectd}, (result) => {
                 obj = JSON.parse(result);
                 if (obj.error == true) {
                     document.getElementById('msg').innerHTML = obj.msg;
                 }
                 else
                     document.getElementById('msg').innerHTML = 'Publication has been added';
             }).done(() => {
                 alert('request is done');
             }).fail(() => {
                 alert('request is fail');
            });
         // using jquery.ajax() to send post request
            $.ajax({
                url : 'https://xxxxxx.com/camera/save',
                method : 'POST',
                data : {
                    'img' : img, 'pub' : pb, 'stick' : stickSelectd
                },
                headers : "Content-type : image/png",
                Success : (result) => {
                    alert(result);
                },
                err : () => {
                    alert('error');
                }
            });
        }
    </script>

.htaccess I know too many risks for allow-origin "*" but i use it just for testing.

Header Set Access-Control-Allow-Origin "*"

always request sending by $.post() alert 'request is fail' and sometimes the request is received from the server and save the image but the meme respond is getting ('request is fail').

there is all fine in my code or i miss something like headers, .. ?? and thanks for helping

ajax .htaccess request xmlhttprequest .post
Original Q&A
1

There are 1 best solutions below

0
oboualla oboualla On 27 September 2020 at 03:30

it works now with ajax(), i change the function pub to :

function pub(img, pb) {
            $.ajax({
                url : 'https://xxxxxxxx.com/camera/save',
                method : 'POST',
                data : {
                    'img' : img, 'pub' : pb, 'stick' : stickSelectd
                },
                headers : "Content-type : image/png"
            }).done((result) => {
                obj = JSON.parse(result);
                if (obj.error == true) {
                    document.getElementById('msg').innerHTML = obj.msg;
                }
                else
                    document.getElementById('msg').innerHTML = 'Publication has been added';
            }).fail(() => {
                document.getElementById('msg').innerHTML = 'something wrong !! try again';
            })
        }

i don't know why the old syntax doesn't work, I think it fine ?!

Related Questions in AJAX

  • window.location.href redirects but is causing problems on the webpage
  • Js variable to php using ajax
  • TypeError: Failed to execute 'arrayBuffer' on 'Blob': Illegal invocation - Insert blob into database
  • how do I change a URL with form to include additional selection
  • why i have to put extra space in before write option selected because it show error if i don't ' option:selected'
  • Opening modal through Update button with specified ID using ajax
  • Events disappear randomly for full calendar module
  • Ajax call reloads page in FrontAccounting, a PHP ERP solution
  • Add newly added record to select2 element
  • AJAX query cascading dropdown in django
  • Failed to load resource: the server responded with a status of 403 () - SCRIPT - WordPress
  • Maintaining search and sort state across paginated results in web application
  • Getting POST 500 Internal server error while sending request via ajax call
  • Wordpress server side datatable filtering
  • Having a problem in datatables and fullcalendar scripts

Related Questions in .HTACCESS

  • Special access rule in an .htaccess file for IP addresses, authorized only for one directory structure
  • Check REQUEST_URI for any /nl/ or /en/ to change my RewriteRules
  • How to ignore case in regexp mapping in a .htaccess rewrite rule?
  • Use htaccess to add subdirectory to url while displaying base url
  • Making a POST to a folder are recived as a GET
  • Missing Headers Security Report .htaccess
  • I can't retrieve GET values
  • Ionic local CORS error, yet headers are set
  • htaccess rewrite rule - if the parameter value has forward slashes
  • How to configure .htaccess file for two different websites routing in my shared hosting server
  • Blank page after Create React App Build placed on server
  • How to redirect to the landing page when the domain name is searched?
  • problem with htaccess RewriteRule with parameters
  • WordPress Multisite Subdomain showing error 404
  • htaccess config to serve jxl / avif if file exist

Related Questions in REQUEST

  • Handling both JSON and form values in POST request body with unknown values in Golang
  • beautifulsoup library not showing below #document data inside iframe tag in python
  • Trouble Extracting Request Body in Flask-Lambda Application Deployed on AWS Lambda via AWS SAM
  • pagination, next page with scrapy
  • Can we pass a hostname/IP address as a query string in a GET request in REST API
  • How to properly extend the generic interface with a new generic parametr using decration merging in Typescript?
  • ReadTimeout error when downloading images on AWS EC2 but not locally
  • How to intercept a request made by a form submit in JavaScript?
  • Unregistered urls in flask logs
  • Masking in logback.xml with all request and responses
  • Making a POST to a folder are recived as a GET
  • Changing PHP code which uses PHPs $_REQUEST super global
  • How to send huge JSON with PDF encoded over HTTPS in JMeter?
  • i have intergrated daraja api with by booking app coded in java but in payments page it toasts an error message Error:Failed to initiate payment
  • Can input arguments be passed to an httpyac file?

Related Questions in XMLHTTPREQUEST

  • How can I prevent the password from appearing in the network tab payload?
  • Cannot interact with netcat server over distance
  • How to alter contents of the XHR object returned to Angular application from the middleware in C#?
  • jQuery Ajax data server capacity problem with 503 errors
  • I had to save a canvas drawing but my POST request is blocked by CORS problem
  • How to intercept all network requests in a web page
  • Why is my XMLHttpRequest progress console log not showing?
  • Is it possible to log specific resason for Network Error for failed HTTP in browser(Chrome)
  • VBA macro not able to call API second time
  • How do I determine scope in an XMLHttp callback function
  • Why can I get access to an audio file but not a text file in a website?
  • Send the value js to php
  • Different boundary in multipart/form-data header and request body using XMLHttpRequest
  • Debugging Ajax/XmlHttpRequests using Xdebug on Sublime
  • Why does Axios.get(URL) not return consistently?

Related Questions in .POST

  • Post request returning homepage for subset of users
  • $.ajax is not a function ( on full version of jQuery )
  • jquery $.post() via REST router not setting $_SERVER['REQUEST_METHOD']?
  • Delete button not sending data through Ajax
  • Ajax .post() method doesn't send data to the server
  • "$.post is not a function" in IBM Watson Assistant chatbot
  • JQuery $.post is not sending data to my php - AJAX problem
  • Button Value outside of the Form is not being posted
  • run functions one by one after each other like async but without async
  • Something wrong , sending post request using jquery.post()
  • jquery $.post with Twitter API works, but callback function is not returning data
  • $.post stopped working after DNS/SSL change (edited)
  • Getting values from jQuery object array based on key not array number
  • i cannot use the router.post method in node.js
  • Problem receiving the response from a .post

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

Popular # Hahtags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs node.js arrays c asp.net json

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?

Copyright © 2021 Jogjafile Inc.

  • Disclaimer
  • Privacy
  • TOS
  • Homegardensmart
  • Pricesm.com
  • Aftereffectstemplates