No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. FraserMcT
    F
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Best 0
    • Groups 0

    FraserMcT

    @FraserMcT

    0
    Reputation
    8
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    FraserMcT Follow

    Latest posts made by FraserMcT

    • RE: Axios - sending json to php page

      @metalsadman - thank you very much!
      I have to admit my stupidity - I have been making my life difficult by saving the variable as a file to view the contents - not realising that I could echo as a response. I also thought that by having quotes in the json that it made it invalid, but it didn’t.
      Thank you for your patience and for your help.

      posted in Help
      F
      FraserMcT
    • RE: Axios - sending json to php page

      @metalsadman I had tried this previously, however the json wasn’t sending as it should. See what I get with the suggested. I don’t think this is valid? But as I said I’m new to axios and ajax… This is from the console log

      {
        "data": "Message sent.",
        "status": 200,
        "statusText": "OK",
        "headers": {
          "date": "Fri, 07 Jun 2019 17:38:02 GMT",
          "server": "nginx",
          "connection": "close",
          "transfer-encoding": "chunked",
          "content-type": "application/json"
        },
        "config": {
          "url": "sendto.php",
          "method": "post",
          "data": "{\"name\":\"fraser\",\"email\":\"email@email.com\",\"message\":\"testing this\"}",
          "headers": {
            "Accept": "application/json",
            "Content-Type": "application/json"
          },
          "transformRequest": [
            null
          ],
          "transformResponse": [
            null
          ],
          "timeout": 0,
          "xsrfCookieName": "XSRF-TOKEN",
          "xsrfHeaderName": "X-XSRF-TOKEN",
          "maxContentLength": -1
        },
        "request": {}
      }
      
      posted in Help
      F
      FraserMcT
    • RE: Axios - sending json to php page

      I took the JSON from the console log above - it is status 200. Is this what you are asking for ? Or am I missing something?

      posted in Help
      F
      FraserMcT
    • RE: Axios - sending json to php page

      Thanks metalsadman, however this didn’t work for me.

      posted in Help
      F
      FraserMcT
    • Axios - sending json to php page

      Hello,
      I’ve set up an axios post request to a php script - this is to send an email (simple! or so I would have thought)
      My script seems to be working correctly, as I can save the json to a seperate file and retrieve the information via the php script.
      Therefore I think there might something wrong with the post request?
      Here is the js:

          onSubmit (name, email, message) {
            const newdata = {
              name: this.name,
              email: this.email,
              message: this.message
            }
      
            this.$axios.post('linkto.php', null, { headers: {'Content-Type': 'application/json'}, params: newdata })
      
              .then(response => {
                console.log(response)
              })
              .catch(error => {
                console.log(error)
              })
              .finally(function () {
              })
          },
      

      And this is an example of the json:

      {
        "data": "Message sent.",
        "status": 200,
        "statusText": "OK",
        "headers": {
          "date": "Thu, 06 Jun 2019 22:50:43 GMT",
          "server": "nginx",
          "connection": "close",
          "transfer-encoding": "chunked",
          "content-type": "application/json"
        },
        "config": {
          "url": "linkto.php",
          "method": "post",
          "params": {
            "name": "Fraser",
            "email": "testg@gmail.com",
            "message": "message"
          },
          "data": null,
          "headers": {
            "Accept": "application/json",
            "Content-Type": "application/json"
          },
          "transformRequest": [
            null
          ],
          "transformResponse": [
            null
          ],
          "timeout": 0,
          "xsrfCookieName": "XSRF-TOKEN",
          "xsrfHeaderName": "X-XSRF-TOKEN",
          "maxContentLength": -1
        },
        "request": {}
      }
      

      php file for ref

      $json_str = file_get_contents('php://input');
      $json_obj = json_decode($json_str);
      echo $json_obj['params']['name'];
      

      I’ve been scratching my head for days now, but am new to axios, quasar and vue!

      Thanks for any help given.

      posted in Help
      F
      FraserMcT