我有以下代码用于显示由php文件引发的json响应,当我在控制台上显示它时,它给了我TypeError:在'操作数e中无效'
Json的回应:
[{"keyword":"free dental care","svol":27100},{"keyword":"low cost dental care","svol":2900}]
JQuery的:
$('#specialty').change(function(){
var spevalue=$( "#specialty option:selected" ).text();
var dataString='specialty='+ spevalue;
$.ajax({
type:"post",
datatype : 'json',
url:"GetKeyWordBids.php",
data:"specialty="+ spevalue,
success: function(data) {
$.each(data, function( index, value ) {
console.log(value.keyword);
});
},
});
});
回应:
TypeError: invalid 'in' operand e
GetKeyWordBids.php
<?php
require_once dirname(__FILE__).'/googleads-php-lib-master/examples/AdWords/v201409/init.php';
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
*/
$specialty=$_POST['specialty'];
$ret=array();
// Include the initialization file
require_once UTIL_PATH . '/MapUtils.php';
function GetKeywordIdeasExample(AdWordsUser $user) {
global $ret;
$ret=array();
// Get the service, which loads the required classes.
$targetingIdeaService =
$user->GetService('TargetingIdeaService', ADWORDS_VERSION);
// Create seed keyword.
$keyword =$_POST['specialty'];
// Create selector.
$selector = new TargetingIdeaSelector();
$selector->requestType = 'IDEAS';
$selector->ideaType = 'KEYWORD';
$selector->requestedAttributeTypes = array('KEYWORD_TEXT', 'SEARCH_VOLUME',
'CATEGORY_PRODUCTS_AND_SERVICES');
// Create language search parameter (optional).
// The ID can be found in the documentation:
// https://developers.google.com/adwords/api/docs/appendix/languagecodes
// Note: As of v201302, only a single language parameter is allowed.
$languageParameter = new LanguageSearchParameter();
$english = new Language();
$english->id = 1000;
$languageParameter->languages = array($english);
// Create related to query search parameter.
$relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
$relatedToQuerySearchParameter->queries = array($keyword);
$selector->searchParameters[] = $relatedToQuerySearchParameter;
$selector->searchParameters[] = $languageParameter;
// Set selector paging (required by this service).
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
do {
// Make the get request.
$page = $targetingIdeaService->get($selector);
// Display results.
if (isset($page->entries)) {
foreach ($page->entries as $targetingIdea) {
$data = MapUtils::GetMap($targetingIdea->data);
$keyword = $data['KEYWORD_TEXT']->value;
$search_volume = isset($data['SEARCH_VOLUME']->value)
? $data['SEARCH_VOLUME']->value : 0;
$categoryIds =
implode(', ', $data['CATEGORY_PRODUCTS_AND_SERVICES']->value);
// printf("Keyword idea with text '%s', category IDs (%s) and average "
//. "monthly search volume '%s' was found.\n",
// $keyword, $categoryIds, $search_volume);
array_push($ret,array("keyword"=>$keyword,"svol"=>$search_volume));
//$temp=array();
//$ret = array_merge($ret, array("keyword"=>$keyword,"svol"=>$search_volume));
//array_push($ret,$temp);
//$json=json_encode($temp);
//array_push($ret,$json);
}
//print_r($ret);
echo json_encode($ret);
}
else {
print "No keywords ideas were found.\n";
}
// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
}
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
// Log every SOAP XML request and response.
$user->LogAll();
//$user->SetClientCustomerId(3310773561);
// Run the example.
GetKeywordIdeasExample($user);
} catch (Exception $e) {
printf("An error has occurred: %s\n", $e->getMessage());
}