Aus Jquery PUT wird im Browser GET

jemand anders

Erfahrenes Mitglied
Hallo,

während ein Update, das ich machen will, auf der Konsole mit CURL klappt, komme ich im Browser mit JS nicht weiter. Statt einer Erfolgsmeldung (JSON zig Werten) erscheint immer
Code:
{
   message: "Not Found",
   documentation_url: "https://developer.github.com/v3"
}

Gerade sah ich nun, dass offenbar aus der in jQueryAjax Methode PUT ein GET wird im Browser, bei Firefox und Chrome (Request Method: GET).

Konsole:
Code:
curl -X PUT -g 'https://api.github.com/repos/USER/REPO/contents/PATH/FILE.json?access_token=TOKEN' -d '{
   "message": "update from api",
   "committer": {
    "name": "USER",
    "email": "USER@MAIL.com"
   },
   "content": "xyz", // => format base64
   "sha": "abc",
   "branch": "gh-pages"
   }'
Browser:
Code:
$.ajax({
      url: "https://api.github.com/repos/USER/REPO/contents/PATH/FILE.json?access_token=TOKEN",
      contentType: "application/json",
      dataType: "jsonp",
      type: "PUT",
      data: jsonData, // => object; content format base64
      success: function (data) {
           console.log(data.data);
      },
      error: function (error) {       
           console.log(error);
      }
   });

Jemand eine Idee?

Grüße
 
Ganz einfach weil es nicht type ist, sondern method.
Wenn method nicht gesetzt ist, dann wird automatisch Get genutzt.

Code:
$.ajax({
      url: "https://api.github.com/repos/USER/REPO/contents/PATH/FILE.json?access_token=TOKEN",
      contentType: "application/json",
      dataType: "jsonp",
      method: "PUT",
      data: jsonData, // => object; content format base64
      success: function (data) {
           console.log(data.data);
      },
      error: function (error) {      
           console.log(error);
      }
   });
 
Hm, dann habe ich da wohl etwas falsch verstanden:
  • method (default: 'GET')
    Type: String
    The HTTP method to use for the request (e.g. "POST", "GET", "PUT"). (version added: 1.9.0)
  • type (default: 'GET')
    Type: String
    An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0.
http://api.jquery.com/jQuery.ajax/
Ich verwende https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js.

Habe ich geändert, ist aber kein Unterschied.
 
Zuletzt bearbeitet:
Lösung:
Code:
$.ajax({
        url: "https://api.github.com/repos/USER/l1/contents/PATH/FILE.json?access_token="+accessToken,
        type: "PUT",
        data: '{"message":"update from api","committer":{"name":"USER","email":"USER@MAIL.com"},"content":"' + contentBase64 + '","sha":"' + sha + '","branch":"gh-pages"}',
        success: function (data) {
              console.log...    
        },
        error: function (error) {    
            console.log...
        }
    });
Der sha des bisherigen Contents wird vorher geholt, und contentBase64 ist der mit b64EncodeUnicode kodierte neue Content.
 
Zurück