0

こんにちは以下は、jqueryのajax呼び出しを介して関数1を呼び出しているコードです:「setEmailAFriendCount」では、jsonデータ型を持つ変数を送信していますが、ajax呼び出しから同じ関数を呼び出したいが、余分な文字列パラメーターを送信する必要があります.

どうやって送ろうか迷っています。P

function getEmailAFriendCountDynamic(ArticleURL, Id) {
        alert('Hi');
        var location = ArticleURL;
        if (location.indexOf('?') >= 0) {
            location = location.substring(0, location.indexOf('?'));
        }

        $.ajax({
            url: 'http://contactimporter.mercola.com/EmailArticleCount.aspx?url=' + location,
            dataType: "jsonp",
            jsonpCallback: "setEmailAFriendCount"
        });
    }
Function 1:

function setEmailAFriendCount(json) {
        $('#MyTextbox').text(json.count);
    }
Function 2:
    function setEmailAFriendCount(json,emailtofrdclientid) {
        $('#' + emailtofrdclientid + '').text(" : " + json.count);
    }
4

2 に答える 2

0
function getEmailAFriendCountDynamic(ArticleURL, Id) {
        alert('Hi');
        var location = ArticleURL,
            self = this;
        if (location.indexOf('?') >= 0) {
            location = location.substring(0, location.indexOf('?'));
        }

        $.ajax({
            url: 'http://contactimporter.mercola.com/EmailArticleCount.aspx?url=' + location,
            dataType: "jsonp",
            jsonpCallback: "setEmailAFriendCount",
            success: function(jData) {
                 self.setEmailAFriendCount(jData, Id);
              }
        });
    }

Function 1:

function setEmailAFriendCount(json) {
        $('#MyTextbox').text(json.count);
    }
Function 2:
    function setEmailAFriendCount(json,emailtofrdclientid) {
        $('#' + emailtofrdclientid + '').text(" : " + json.count);
    }

このコードはあなたが探しているものだと思います...

于 2012-05-28T06:43:23.200 に答える
0

コールバック パラメータはサーバー側で作成されます。複数のパラメーターを返したい場合は、必要な数のパラメーターを持つjsonオブジェクトを返します。戻り値はそのオブジェクトを取得し、正しく解析する必要があります。マルチパラメーターをサーバーに送信するには、json オブジェクトを送信し、それをdataプロパティの下に渡します。

$.ajax({
  type: "[GET/POST]",
  url: "[your url]",
  data: { name: "John", location: "Boston" }, //your object here
  success: function(data) {
    //parse your json return data here
  }
});

jQuery ajaxの詳細については、こちらをご覧ください。

于 2012-05-28T06:28:14.070 に答える