How to use type: “POST” in jsonp ajax call

后端 未结 6 2210
半阙折子戏
半阙折子戏 2020-11-22 13:11

I am using JQuery ajax jsonp. I have got below JQuery Code:

 $.ajax({  
        type:\"GET\",        
        url: \"Login.aspx\",  // Send          


        
6条回答
  •  旧时难觅i
    2020-11-22 13:47

    Here is the JSONP I wrote to share with everyone:

    the page to send req
    http://c64.tw/r20/eqDiv/fr64.html

    please save the srec below to .html youself
    c64.tw/r20/eqDiv/src/fr64.txt
    the page to resp, please save the srec below to .jsp youself
    c64.tw/r20/eqDiv/src/doFr64.txt

    or embedded the code in your page:

    function callbackForJsonp(resp) {

    var elemDivResp = $("#idForDivResp");
    elemDivResp.empty();
    
    try {
    
        elemDivResp.html($("#idForF1").val() + " + " + $("#idForF2").val() + "
    "); elemDivResp.append(" = " + resp.ans + "
    "); elemDivResp.append(" = " + resp.ans2 + "
    "); } catch (e) { alert("callbackForJsonp=" + e); }

    }

    $(document).ready(function() {

    var testUrl = "http://c64.tw/r20/eqDiv/doFr64.jsp?callback=?";
    
    $(document.body).prepend("post to " + testUrl + "

    "); $("#idForBtnToGo").click(function() { $.ajax({ url : testUrl, type : "POST", data : { f1 : $("#idForF1").val(), f2 : $("#idForF2").val(), op : "add" }, dataType : "jsonp", crossDomain : true, //jsonpCallback : "callbackForJsonp", success : callbackForJsonp, //success : function(resp) { //console.log("Yes, you success"); //callbackForJsonp(resp); //}, error : function(XMLHttpRequest, status, err) { console.log(XMLHttpRequest.status + "\n" + err); //alert(XMLHttpRequest.status + "\n" + err); } }); });

    });

提交回复
热议问题